Showing posts with label containing. Show all posts
Showing posts with label containing. Show all posts

Wednesday, March 28, 2012

Accessing SelectedIndex of Datagrid inside a bound Accordion Control

I have a bound Accordion Control with its Content Template containing a gridview. Each Gridview is populated on the Accordion ItemDataBound.

The Gridview containes a set of bound checkboxes with autopostback set to true.

When a checkbox is clicked i need to find the selectedindex of the row in the gridview in question. I'm trying to retreive the selected index from within the form load event.

Any ideas?

Just to let you know, if you have your checkbox inside the GridView, you have to find the control within the GridView first and then see what is the selected value or index.

CheckBox myCheckBox = (CheckBox) GridView1.FindControl("myCheckBox1");

int i = myCheckBox.SelectedIndex;

Just one more thing, Enable Tracing for your page Trace="true" in the <%@.Page Language=... so you can see what is the name for your control. Because if you are using master page the names would be auto generated with a prefix.

Hope this would be any help to you.

Regards,
Mehdi


Just to let you know, if you have your checkbox inside the GridView, you have to find the control within the GridView first and then see what is the selected value or index.

CheckBox myCheckBox = (CheckBox) GridView1.FindControl("myCheckBox1");

int i = myCheckBox.SelectedIndex;

Just one more thing, Enable Tracing for your page Trace="true" in the <%@.Page Language=... so you can see what is the name for your control. Because if you are using master page the names would be auto generated with a prefix.

Hope this would be any help to you.

Regards,
Mehdi


Thanks for the reply.

It doesn't realy help as firstly I need to find the gridview within the accordion control, then find the datakey of the row (checkbox) that's been clicked on.

I'm not sure how to index the accordion control as it's bound and doesn't use the panes collection?

Wednesday, March 21, 2012

A lil tab issue

I have a selection of ajax tabs each containing diffrent gridviews of data. Each gridview has a template feild with a linkbutton inside of it, the link buttons command ends with a page reload if you will that looks something like this :


Response.Redirect("~/Home/Editor?pid=" + QueryStringPID);

When i click the linkbutton the page doesnt go back to the editor?pid=1 for example. even though that line is within the code... i dont understand it. i tryed putting an update panel within the tab to see if that would help but it doesnt seem to work. The link buttons on_click event isnt strickly an on_click as its a RowCommand. It simply checks the command name and changes it from 1 to 0 or 0 to 1, it worked perfectly well out side of the tab. which is confusing.

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BlinkConnectionString"].ToString());
SqlCommand Command = new SqlCommand();
Command.Connection = Connection;
Connection.Open();
if (e.CommandName == "0")
{
Command.CommandText = "UPDATE Profile SET " + e.CommandArgument + " = '1' WHERE UserID = " + QueryStringPID;
Command.ExecuteNonQuery();
}
else if (e.CommandName == "1")
{
Command.CommandText = "UPDATE Profile SET " + e.CommandArgument + " = '0' WHERE UserID = " + QueryStringPID;
Command.ExecuteNonQuery();
}
Connection.Close();
Response.Redirect("~/Home/Editor?pid=" + QueryStringPID);
}

Any ideas all are welcome! thanks si!

ps does anyone know how to force a postback for an update panel? thanks si!

sorted it, no worries thanks for anyone who was making an attempt at sorting it! si!