Hello,
"Loaded usercontrol has a gridview whose selection is not showing in postback"
I have a page main.aspx.cs that loads at runtime web controls (.ascx)
One of the controls has a gridview and when I select an item in the gridview I want
to use this value in the main page (the main.aspx.cs) I have everything turned on
(enable viewstate =true for the gridview)
I tried on selected index changed and selected index changing event handlers to
assign the gridview1.selectedvalue to the viewstate but wasn't able to get anything
in the postback instance of the page.
I was able to add the value to the session but not the viewstate. I can also add
it to the page.form.attributes and recall it in the postback
The problem in the "page.form.attributes " is that the value called in the postback
is not the last selected index, but it is delayed by 2 selected indexes, so it gives
-1, 1, 2 instead of 1, 2 at consecutive postbacks when selecting first and second
rows
(this is new)
I tried to response.write in the loaded control the value of gridview1.selected
index on the control's page load event and it gives a delay of 1 browser trip
ramzi1978 at hotmail thanks
Loading
ramzi hawaPosted Jun 6, 2007, 10:21 AM
help plz
ramzi hawaPosted May 29, 2007, 8:48 AM
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrowstyle(VS.80).aspx
you need to use the gridview row
void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
{
// Get the currently selected row using the SelectedRow property.
GridViewRow row = CustomersGridView.SelectedRow;
// Display the company name from the selected row.
// In this example, the third column (index 2) contains
// the company name.
Response.Write( "You selected " + row.Cells[2].Text + ".");
void CustomersGridView_SelectedIndexChanging(Object sender,
GridViewSelectEventArgs e)
{
// Get the currently selected row. Because the SelectedIndexChanging event
// occurs before the select operation in the GridView control, the
// SelectedRow property cannot be used. Instead, use the Rows collection
// and the NewSelectedIndex property of the e argument passed to this
// event handler.
GridViewRow row = CustomersGridView.Rows[e.NewSelectedIndex];
// You can cancel the select operation by using the Cancel
// property. For this example, if the user selects a customer with
// the ID "ANATR", the select operation is canceled and an error message
// is displayed.
if (row.Cells[1].Text == "ANATR")
{
e.Cancel = true;
Response.Write( "You cannot select " + row.Cells[2].Text + ".");
}}
ramzi hawaPosted May 28, 2007, 4:56 PM
add a gridview that reads from a test database
with select enabled, viewstate=true; add on load response.write(gridview1.selectedindex.ToString());
press F5 and click on an item
you have to click again to see the correct selected index
any ideas?
if i add a dropdown, when i select and then i select in the gridview, the
response.write dropdownlist1.selectedindex is correct
thanks
ramzi hawaPosted May 25, 2007, 12:29 PM
PS: I am not receiving a notification email when this post is updated
Ziaul HaquePosted May 21, 2007, 4:42 AM
Can you tell me one thing that where you have add ur user control. Is it in Init event or Load or Pre Rendering or u have added it in design time.