Subscribe to Subscribers
Talk to Webmaster Tony John

Forums » .NET » ASP.NET »

How to get multiple values from table into textbox using ajax concepts


Posted Date: 12 Jul 2012      Posted By:: chellappan     Member Level: Silver    Member Rank: 1417     Points: 2   Responses: 3



hi all,

I need code using ajax.

how to get multiple values from table into textbox using ajax concepts

Thanks and Regards,

AL.Chellappan




Responses

#680079    Author: Kapil      Member Level: Gold      Member Rank: 51     Date: 12/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

I will suggest to have ASP.net WebService which will return you the data from the database and pass that to Ajax call from your JavaScript.

You can use the JSON (JavaScript Object Notation) or just the return data from that Web Service.

How to use Ajax with WebService you can read my blog.

Happy Coding

"Please don't forget to Rate this answer if you found it usefull"

http://www.dotnetspider.com/mentors/86-kapil-deo.aspx
My Blog



 
#680093    Author: Paritosh Mohapatra      Member Level: Diamond      Member Rank: 6     Date: 12/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

You can use Ajax AutoComplete Extender control for this purpose. For getting the data from the database you need to create a Web Service in your application nd associate that Web Service with the Ajax AutoComplete Extender control.

Please check the following code:

WebService.cs
-------------


/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

public WebService()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string[] GetNames(string prefixText, int count)
{
List<string> KeyValue = new List<string>();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ToString());
count = 10;
string str = "SELECT sid,sname FROM student WHERE sname like '" + prefixText + "%'";
con.Open();
SqlCommand com = new SqlCommand(str, con);
SqlDataReader dr = com.ExecuteReader();
int i = 0;
if (dr.HasRows)
{
while (dr.Read())
{
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["sname"].ToString(), dr["sid"].ToString());
KeyValue.Add(item);
i++;
}
}
return KeyValue.ToArray();
}
}


Default.aspx
------------


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function GetKey(source, eventArgs)
{
document.getElementById("LblKey").innerText = eventArgs.get_value();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
ServicePath="WebService.asmx" ServiceMethod="GetNames" MinimumPrefixLength="0"
CompletionInterval="100" EnableCaching="true" CompletionSetCount="12" OnClientItemSelected="GetKey">
</asp:AutoCompleteExtender>
<asp:Label ID="LblKey" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>



Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM



 
#680127    Author: chandramohan      Member Level: Gold      Member Rank: 221     Date: 12/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Check Username availability Using Ajax</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="PnlUsrDetails" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
UserName:
</td>
<td>
<asp:TextBox ID="txtUsername" runat="server" AutoPostBack="true" ontextchanged="txtUsername_TextChanged"/>
</td>
<td>
<div id="checkusername" runat="server" Visible="false">
<asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px"/>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>



protected void txtUsername_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtUsername.Text))
{
SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName=@Name", con);
cmd.Parameters.AddWithValue("@Name", txtUsername.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
checkusername.Visible = true;
imgstatus.ImageUrl = "NotAvailable.jpg";
lblStatus.Text = "UserName Already Taken";
}
else
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Icon_Available.gif";
lblStatus.Text = "UserName Available";
}
}
else
{
checkusername.Visible = false;
}
}






 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Main menu problem in Browser
Previous : How to provide Next previous Grid paging in grid view
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.