Showing posts with label Gridview. Show all posts
Showing posts with label Gridview. Show all posts

Thursday, July 15, 2010

Taking index of a row in Gridview using RowCommand

For taking data using rowcommand property....

When you create the code of Gridview place the code like this for your customized Controls(Button)


<asp:imagebutton id="imgProfile" width="100px" height="100px" runat="server" imageurl="'<%#">' CommandName="cmdImage" CommandArgument='<%# Container.DataItemIndex %>' />
Here look at the COmmand argument property it should be like this. Then only we can take the Index of the Gridview.

Now, in Code behind you can call it like this....

string name = ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("TextBoxName")).Text;

thus you can work on it getting the index of the row.

Fetch data from Footer of Gridview

Taking data from the Footer of a Gridview control in asp.net

GridViewRow row = GridView1.FooterRow;
if (e.CommandName == "cmdSUBMIT")
{
string name = ((TextBox)row.FindControl("TextBoxName")).Text;
Response.Write(name);
}