开发者

Setting a footer without GridViewCommandEventArgs in asp.net

I have a gridview.The footer has a label开发者_如何学运维.Inside a function i just have to set the label..Now I don't have a e (GridViewCommandEventArgs) ,since its not triggered by some event.This is my code

`GridViewRow footer = (GridViewRow)CartGrid.FooterRow;
 Label Total = (Label)footer.FindControl("lblTotal")
 Total.Text = sum.ToString();`

I am getting the error -> 'Object reference not set to an instance of an object.'

CartGrid is the gridview. lblTotal is the label. sum has the content for label.


You can use RowCreated or RowDataBound event. For example,

void CartGrid_RowCreated(Object sender, GridViewRowEventArgs e)
{
   if (r.Row.RowType == DataControlRowType.Footer)
   {
      ...
   }
}


You have to bind the grid to a data source before you set footer value.

I have mentioned this in a comment but I was reviewing of my stalkoverflow profile and I saw this question unanswered and unclosed.So have pasted the link to the answer once again.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜