I am aspx page in which I have added a datalist. Inside the datalist, I have a dynamic anchor tags. On click of the anchor tag, I am getting the data from sql database and bind to a gridview. The anchor tags are shown inside the div id "phss". The anchor
tags are created from code behind.
I have tried the below code, but the gridview is not getting displayed with the data. I can see the data in the dataset.
// code behind
// In item bound, the anchor links are created as below
foreach (var catmemb in jsonBulkMembers.items[j][property1].items)
{
text += "<a id='schema' href='#' onclick='win(this)'>" + jsonBulkMembers.items[j][property1].items[k]._name + "</a> ";
if (k != 0 && k % 5 == 0)
{ text += "<br/>"; }
k++;
}
// On click of the anchor link, a javascript function is called
function win(anchor) {
var SchemaName = anchor.innerHTML;
PageMethods.getDetails(SchemaName,On_Success, On_Failure);
}
//getDetails method in code behind
[WebMethod]
public static void getDetails(string schemaname)
{
Sample temp = new Sample();
Sample.NonStaticDelegate = new Action(temp.NonStaticMethod);
if (Sample.NonStaticDelegate != null)
{
Sample.NonStaticDelegate();
}
}
public void NonStaticMethod()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection Name"].ToString());
using (con)
{
SqlCommand cmd = new SqlCommand("stored procedure");
DataSet ds = new DataSet();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DataTableName", "test12");
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView grdsc = (GridView)DlSearch.SelectedItem.FindControl("grdsc");
grdsc.DataSource = ds.Tables[0];
grdsc.DataBind();
}
}
According to your description, as far as I know, you call win() in JS, you set dataset in NonStaticMethod(), but it is a local variable, dataset need return to JS function, then them to GridView! That is why you can see data in dataset, but can not bind
them in gridview! About how to bind them in GridView, you can refer to this link:
Bind data to GridView with jQuery or JSON in ASP.Net:
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
According to your further description, I suggest you can upload your demo to OneDrive(Including your test material). I can download it and debugging. This will help you quickly analyze the problem.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Participant
1443 Points
2030 Posts
Gridview not binding
Nov 17, 2016 09:29 AM|venkatzeus|LINK
Hi,
I am aspx page in which I have added a datalist. Inside the datalist, I have a dynamic anchor tags. On click of the anchor tag, I am getting the data from sql database and bind to a gridview. The anchor tags are shown inside the div id "phss". The anchor tags are created from code behind.
I have tried the below code, but the gridview is not getting displayed with the data. I can see the data in the dataset.
How to fix this?
Thanks
Contributor
6730 Points
2715 Posts
Re: Gridview not binding
Nov 18, 2016 12:19 PM|Eric Du|LINK
Hi venkatzeus,
According to your description, as far as I know, you call win() in JS, you set dataset in NonStaticMethod(), but it is a local variable, dataset need return to JS function, then them to GridView! That is why you can see data in dataset, but can not bind them in gridview! About how to bind them in GridView, you can refer to this link:
Bind data to GridView with jQuery or JSON in ASP.Net:
http://www.aspsnippets.com/Articles/Bind-data-to-GridView-with-jQuery-or-JSON-in-ASPNet.aspx
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Participant
1443 Points
2030 Posts
Re: Gridview not binding
Nov 24, 2016 12:39 PM|venkatzeus|LINK
Hi Eric Du,
Your answer helped me alot. I am now able to bind the data.
I want to show pagination for the gridview which is inside the datalist. Below is the sample aspx:
Below is the javascript function whihc I have used to achieve the paging.
The problem is the div "pager" is showing for every item in the datalist, without the link being selected.
Example:
If i click on Link5, the details of Link5 are shown in gridview with pagination. However, the pagination is also getting shown for "Item1" , "Item2".
The pagination should be shown only for "Link5", which is the selected item.
How to achieve this?
Thanks
Contributor
6730 Points
2715 Posts
Re: Gridview not binding
Dec 05, 2016 05:42 AM|Eric Du|LINK
Hi venkatzeus,
According to your further description, I suggest you can upload your demo to OneDrive(Including your test material). I can download it and debugging. This will help you quickly analyze the problem.
Share OneDrive files and folders:
https://support.office.com/en-us/article/Share-OneDrive-files-and-folders-9fcc2f7d-de0c-4cec-93b0-a82024800c07
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.