开发者

Check the current Row is a data row or not

开发者 https://www.devze.com 2023-01-30 02:28 出处:网络
I have a gridview with 10 rows i am displaying 6 rows in each page i have a text box and and image button in each row when i click the image button all the functionalities are working but when i click

I have a gridview with 10 rows i am displaying 6 rows in each page i have a text box and and image button in each row when i click the image button all the functionalities are working but when i click the page index it is displaying an error in row command how can i check whether the row type is data row or not in gridview row command event. the code that i am using is as follows

protected void gvgridview1_RowCommand(object se开发者_StackOverflow社区nder, GridViewCommandEventArgs e)
    {
      GridViewRow gvRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
      TextBox txtgvGroupName = (TextBox)gvRow.FindControl("txtgvGroupName");
      ImageButton imgbtn = (ImageButton)gvRow.FindControl("imgbtn");
      if (e.CommandName == "Edit")
            {
              imgbtn.Visible = false;
            }
    }


If(e.Row.RowType == DataControlRowType.DataRow)

then write your condition.


a little to do with the datarow here, instead you need to check if (e.CommandSource is ImageButton) at the first line of your gvgridview1_RowCommand


Have you tried checking the RowType property of the GridViewRow instance?


try this assuming you are reffering System.Data.DataRow

GridViewRow gvRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
DataRow drow = gvRow.DataItem as DataRow

if(drow!=null)
 {
     // row is DataRow
 }


Check e.Row.RowType, it allows you to compare the RowType to the DataControlRowType enum.

[EDIT] I wonder if it's something to do with how you're getting hold of the row. The code I just tried is:

GridViewRow row = Gridview.Rows[int.Parse(e.CommandArgument.ToString())];

After that I can use row.RowType quite happliy. Might be worth a try for you.

DataControlRowType

0

精彩评论

暂无评论...
验证码 换一张
取 消