C# 如何申请;只读“;在编辑模式下使用BoundField在gridview文本框中
我想在使用Boundsfield的文本框上设置只读。到目前为止,enabled正在工作,但它在RowUpdate中没有价值C# 如何申请;只读“;在编辑模式下使用BoundField在gridview文本框中,c#,asp.net,gridview,C#,Asp.net,Gridview,我想在使用Boundsfield的文本框上设置只读。到目前为止,enabled正在工作,但它在RowUpdate中没有价值 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { var nopoject = ddlproject.SelectedValue.ToString(); Int32 curntMonth = Convert.ToInt32(Da
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
var nopoject = ddlproject.SelectedValue.ToString();
Int32 curntMonth = Convert.ToInt32(DateTime.Now.ToString("MM"));
int Mont1 = curntMonth - 1;
var Comtext = "Rst" + Mont1.ToString();
GridView1.EditIndex = e.NewEditIndex;
BindData();
foreach (GridViewRow row in GridView1.Rows)
{
for (int i = 0; i < GridView1.Columns.Count; i++)
{
String headertext = GridView1.Columns[i].HeaderText;
String cellText = row.Cells[i].Text;
if (Comtext == "Rst1")
{
GridView1.Rows[e.NewEditIndex].Cells[i].Enabled = true;
}}}
请告知。内联编辑时,我希望以编程方式在boundsfield上设置只读
多谢各位
您还可以在行编辑事件中将文本框设置为只读,如下所示
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
var nopoject = ddlproject.SelectedValue.ToString();
Int32 curntMonth = Convert.ToInt32(DateTime.Now.ToString("MM"));
int Mont1 = curntMonth - 1;
var Comtext = "Rst" + Mont1.ToString();
GridView1.EditIndex = e.NewEditIndex;
BindData();
foreach (GridViewRow row in GridView1.Rows)
{
for (int i = 0; i < GridView1.Columns.Count; i++)
{
String headertext = GridView1.Columns[i].HeaderText;
String cellText = row.Cells[i].Text;
if (Comtext == "Rst1")
{
//GridView1.Rows[e.NewEditIndex].Cells[i].Enabled = true;
TextBox tx_chdets = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl(“TextBox1”);
if(tx_chdets!=null)
{
tx_chdets.Readonly=true;
}
}
}
}
}
protectedvoid GridView1\u行编辑(对象发送方,GridViewEditEventArgs e)
{
var noproject=ddlproject.SelectedValue.ToString();
Int32 curntMonth=Convert.ToInt32(DateTime.Now.ToString(“MM”);
int Mont1=当前月份-1;
var Comtext=“Rst”+Mont1.ToString();
GridView1.EditIndex=e.NewEditIndex;
BindData();
foreach(GridView1.Rows中的GridViewRow行)
{
对于(int i=0;i
您还可以在行编辑事件中将文本框设置为只读,如下所示
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
var nopoject = ddlproject.SelectedValue.ToString();
Int32 curntMonth = Convert.ToInt32(DateTime.Now.ToString("MM"));
int Mont1 = curntMonth - 1;
var Comtext = "Rst" + Mont1.ToString();
GridView1.EditIndex = e.NewEditIndex;
BindData();
foreach (GridViewRow row in GridView1.Rows)
{
for (int i = 0; i < GridView1.Columns.Count; i++)
{
String headertext = GridView1.Columns[i].HeaderText;
String cellText = row.Cells[i].Text;
if (Comtext == "Rst1")
{
//GridView1.Rows[e.NewEditIndex].Cells[i].Enabled = true;
TextBox tx_chdets = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl(“TextBox1”);
if(tx_chdets!=null)
{
tx_chdets.Readonly=true;
}
}
}
}
}
protectedvoid GridView1\u行编辑(对象发送方,GridViewEditEventArgs e)
{
var noproject=ddlproject.SelectedValue.ToString();
Int32 curntMonth=Convert.ToInt32(DateTime.Now.ToString(“MM”);
int Mont1=当前月份-1;
var Comtext=“Rst”+Mont1.ToString();
GridView1.EditIndex=e.NewEditIndex;
BindData();
foreach(GridView1.Rows中的GridViewRow行)
{
对于(int i=0;i
您可以使用此代码段
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
TextBox textBox = e.Row.Cells[0].Controls[0] as TextBox;
textBox.Enabled = false;
}
}
}
您可以使用此代码段
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
TextBox textBox = e.Row.Cells[0].Controls[0] as TextBox;
textBox.Enabled = false;
}
}
}
我只想在编辑的时候收到回信。很抱歉回信迟了。FindControl(“TextBox1”)=如何通过循环查找?@user3538475-我已经编辑了上述代码。请。复习一下。谢谢你……但是。。。tx_chdets返回空值。TextBox tx_chdets=(TextBox)GridView1.Rows[e.NewEditIndex].FindControl(“TextBox1”);在此代码中,用您的文本框Idi替换文本框1。仅当行编辑时,我希望看到。很抱歉回复太晚。FindControl(“TextBox1”)=如何通过循环查找?@user3538475-我已经编辑了上述代码。请。复习一下。谢谢你……但是。。。tx_chdets返回空值。TextBox tx_chdets=(TextBox)GridView1.Rows[e.NewEditIndex].FindControl(“TextBox1”);在此代码中,用文本框Id替换文本框1