User control issues
-
I have a user control with one gridview control on it and the code behind for the user control is shown below
protected void Page_Load(object sender, EventArgs e)
{
gvResults.DataSource = theSource;
gvResults.DataBind();
}private List theSource; public List<string> TheSource { get { return theSource; } set { theSource = value; } }
When I pass value to the control on the page load I works fine with the data being displayed on the grid as shown by the code below
protected void Page_Load(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
DataPager1.TheSource = myData.ToList();
}But when I try to do the same thing by clicking a button, the page shows no data
protected void SearchButton_Click(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
DataPager1.TheSource = myData.ToList();
}DataPager1 is the usercontrol ID. Any help will be appreciated.
-
I have a user control with one gridview control on it and the code behind for the user control is shown below
protected void Page_Load(object sender, EventArgs e)
{
gvResults.DataSource = theSource;
gvResults.DataBind();
}private List theSource; public List<string> TheSource { get { return theSource; } set { theSource = value; } }
When I pass value to the control on the page load I works fine with the data being displayed on the grid as shown by the code below
protected void Page_Load(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
DataPager1.TheSource = myData.ToList();
}But when I try to do the same thing by clicking a button, the page shows no data
protected void SearchButton_Click(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
DataPager1.TheSource = myData.ToList();
}DataPager1 is the usercontrol ID. Any help will be appreciated.
-
You need to rebind the gridview in SearchButton_Click.
thatraja |Chennai|India|
Brainbench certifications
Univotes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-)
My childhood story -
I have a user control with one gridview control on it and the code behind for the user control is shown below
protected void Page_Load(object sender, EventArgs e)
{
gvResults.DataSource = theSource;
gvResults.DataBind();
}private List theSource; public List<string> TheSource { get { return theSource; } set { theSource = value; } }
When I pass value to the control on the page load I works fine with the data being displayed on the grid as shown by the code below
protected void Page_Load(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
DataPager1.TheSource = myData.ToList();
}But when I try to do the same thing by clicking a button, the page shows no data
protected void SearchButton_Click(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
DataPager1.TheSource = myData.ToList();
}DataPager1 is the usercontrol ID. Any help will be appreciated.
I tried it myself, but not success at all with that. I can provide you alternate way. Just change your
SearchButton_Click
event with following snippets.protected void SearchButton_Click(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
//DataPager1.TheSource = myData.ToList();
GridView gview = (GridView)DataPager1.FindControl("gvResults");
gview.DataSource = myData;
gview.DataBind();
}Regards, Hiren. Microsoft Dynamics CRM
My Recent Article: - Way to know which control have raised PostBack[^]
-
I tried it myself, but not success at all with that. I can provide you alternate way. Just change your
SearchButton_Click
event with following snippets.protected void SearchButton_Click(object sender, EventArgs e)
{
string[] myData = {"10", "20", "30"};
//DataPager1.TheSource = myData.ToList();
GridView gview = (GridView)DataPager1.FindControl("gvResults");
gview.DataSource = myData;
gview.DataBind();
}Regards, Hiren. Microsoft Dynamics CRM
My Recent Article: - Way to know which control have raised PostBack[^]
Thanks Hiren for your response, what you posted will work but the only problem is that I need to manipulate the data on the user control, not on the web page itself. So I just wanted a way to pass data from the web page unto the user control and then manipulate it from there. Funny thing is that it works on the Page_Load event but doesn't on the button_click event!
-
Thanks Hiren for your response, what you posted will work but the only problem is that I need to manipulate the data on the user control, not on the web page itself. So I just wanted a way to pass data from the web page unto the user control and then manipulate it from there. Funny thing is that it works on the Page_Load event but doesn't on the button_click event!
Swiftain wrote:
Funny thing is that it works on the Page_Load event but doesn't on the button_click event!
I've experimented a thing already with that, But didn't find any solution for the same, Let me try other way I will let you know once I got the clue. If you're finding the solution then please put here so that it could be useful further for a members and also me.
Regards, Hiren. Microsoft Dynamics CRM
My Recent Article: - Way to know which control have raised PostBack[^]
-
But I don't have access to the gridview in SearchButton_Click I already tried
DataPager1.DataBind();
and it didn't workTry
gvResults.DataSource = theSource; gvResults.DataBind();
SearchButton_Click
thatraja |Chennai|India|
Brainbench certifications
Univotes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-)
My childhood story -
Try
gvResults.DataSource = theSource; gvResults.DataBind();
SearchButton_Click
thatraja |Chennai|India|
Brainbench certifications
Univotes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-)
My childhood story -
Swiftain wrote:
still no luck
I never believe that. what's the error message? mention that too.
thatraja |Chennai|India|
Brainbench certifications
Univotes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-)
My childhood story -
Swiftain wrote:
still no luck
I never believe that. what's the error message? mention that too.
thatraja |Chennai|India|
Brainbench certifications
Univotes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-)
My childhood story -
Thanks Hiren for your response, what you posted will work but the only problem is that I need to manipulate the data on the user control, not on the web page itself. So I just wanted a way to pass data from the web page unto the user control and then manipulate it from there. Funny thing is that it works on the Page_Load event but doesn't on the button_click event!
See THIS[^], It might be useful.
Regards, Hiren. Microsoft Dynamics CRM
My Recent Article: - Way to know which control have raised PostBack[^]
-
See THIS[^], It might be useful.
Regards, Hiren. Microsoft Dynamics CRM
My Recent Article: - Way to know which control have raised PostBack[^]
Instead binding the data on Page_Load event of the user control, I created a method for doing the same thing and it worked. I think the reason is because the Page_Load even of the user control fires and then that of the page fires too which happens automatically, so in order to force a bind, I had to create a simple method like this
public void BindData() { gvResults.DataSource = TheSource; gvResults.DataBind(); }
and then on web page, I just did this
protected void SearchButton\_Click(object sender, EventArgs e) { DataPager1.TheSource = myData.ToList(); DataPager1.BindData(); }
Now that works, but now it looks as though the gridview events from the user control like "OnRowCreated" ain't firing. Oh well, at least I've got one bit working :)
-
Instead binding the data on Page_Load event of the user control, I created a method for doing the same thing and it worked. I think the reason is because the Page_Load even of the user control fires and then that of the page fires too which happens automatically, so in order to force a bind, I had to create a simple method like this
public void BindData() { gvResults.DataSource = TheSource; gvResults.DataBind(); }
and then on web page, I just did this
protected void SearchButton\_Click(object sender, EventArgs e) { DataPager1.TheSource = myData.ToList(); DataPager1.BindData(); }
Now that works, but now it looks as though the gridview events from the user control like "OnRowCreated" ain't firing. Oh well, at least I've got one bit working :)
Yes, That's the way. Thanks for sharing solution.
Swiftain wrote:
"OnRowCreated" ain't firing
Will try to solve it as getting enough time. :)
Regards, Hiren.
My Recent Article: - Way to know which control have raised PostBack
My Recent Tip/Trick: - Remove HTML Tag, get plain Text