在asp.net gridview中检查editindex模式和简单模式的问题 [英] proplem to check editindex mode and simple mode in asp.net gridview
问题描述
我正在使用gridview,并且我正在根据gridview的RowDataBound事件的单元格值更改行的颜色.
我正在使用模板字段ItemTemplate和EditItemTemplate,在ItemTemplate中我使用了Label控件,在EditItemTemplate TextBox中,现在当我加载页面时,它不会显示任何错误,但是当我在gridview上按Edit按钮时,它会给出异常,就像doent找到任何标签控件一样在编辑模式下,
我尝试了如下代码-
I am using a gridview and i am changing the color of row depending on cell value at RowDataBound event of gridview.
I am using template fields, ItemTemplate and EditItemTemplate , in ItemTemplate i have used Label control and in EditItemTemplate TextBox, now when i load page it doesnt show me any error but when i press edit button on gridview it gives exception like doent find any label control in edit mode,
i tried code as follows-
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState != DataControlRowState.Edit)
{
Label lblSalary = (Label)e.Row.FindControl("lblSalary");
decimal Sal = Convert.ToDecimal(lblSalary.Text);
if (Sal > 15000)
{
e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
}
}
但它无法正常工作,请帮助我如何找到ItemTemplate和EditItemTemplate
[edit]将代码包装在前置标签中[/edit]
but its not working properly, please help me how to find ItemTemplate and EditItemTemplate
[edit] wrap code in pre tag[/edit]
推荐答案
将其更改为
chang this as
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState != DataControlRowState.Edit)
{
Label lblSalary = (Label)e.Row.FindControl("lblSalary");
decimal Sal = 0;
if(lblSalary!=null)
{
Sal = Convert.ToDecimal(lblSalary.Text);
}
else
{
TextBox txtSalary = (TextBox)e.Row.FindControl("txtSalary");
Sal=Convert.ToDecimal(txtSalary.Text);
}
if (Sal > 15000)
{
e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
}
}
或者您可以使用 gridview1.editrowindex> = 0
--Pankaj
or you can use gridview1.editrowindex>=0
--Pankaj
这篇关于在asp.net gridview中检查editindex模式和简单模式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!