我怎样才能在GridView控件的RowDataBound的previous行? [英] How can I get the previous row in gridview rowdatabound?
本文介绍了我怎样才能在GridView控件的RowDataBound的previous行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查previous行数据,如果它等于 -
,
如果它不等于 -
然后我会在下一行启用按钮
保护无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
如果(e.Row.RowType == DataControlRowType.DataRow)
{
如果(DataBinder.Eval的(e.Row.DataItemTIME_START)的ToString()== - )
{
按钮BTN =((按钮)e.Row.FindControl(Edit_Button));
btn.Enabled = FALSE;
}
}
}
解决方案
您也可以使用像这样做 GridView1.Rows [e.Row.RowIndex - 1]
保护无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
如果(e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow prevrow = GridView1.Rows [e.Row.RowIndex - 1];
如果(prevrow.RowType == DataControlRowType.DataRow)
{
//你的code操纵prevrow
}
如果(DataBinder.Eval的(e.Row.DataItemTIME_START)的ToString()== - )
{
按钮BTN =((按钮)e.Row.FindControl(Edit_Button));
btn.Enabled = FALSE;
}
}
}
I would like to check the previous row data if it is equal to --
,
if it is not equal to --
then I would enable button in the next row
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (DataBinder.Eval(e.Row.DataItem, "time_start").ToString() == "--")
{
Button btn = ((Button)e.Row.FindControl("Edit_Button"));
btn.Enabled = false;
}
}
}
解决方案
You can also do it like this using GridView1.Rows[e.Row.RowIndex - 1]
.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow prevrow = GridView1.Rows[e.Row.RowIndex - 1];
if( prevrow.RowType == DataControlRowType.DataRow)
{
// Your code for manipulating prevrow
}
if (DataBinder.Eval(e.Row.DataItem, "time_start").ToString() == "--")
{
Button btn = ((Button)e.Row.FindControl("Edit_Button"));
btn.Enabled = false;
}
}
}
这篇关于我怎样才能在GridView控件的RowDataBound的previous行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文