更新时间:2023-01-11 12:38:27
您好b $ b
下面是实现您功能的粗略代码
Hi
Below is rough code that implements your functionality
function ToggleTextBox(checkid,textid) {
var checkBox = document.getElementById(checkid);
if (checkBox.checked)
{
document.getElementById(textid).style.visibility = 'visible';
}
else
{
document.getElementById(textid).style.visibility = 'hidden';
}
}
网格视图定义
Grid View Definition
<asp:gridview runat="server" id="grid" onrowdatabound="RowDataBoundEvent" xmlns:asp="#unknown">
<columns>
<asp:templatefield headertext="Check">
<itemtemplate>
<asp:checkbox runat="server" id="cbSelect" checked="false" />
</itemtemplate>
</asp:templatefield>
<asp:templatefield headertext="B1">
<itemtemplate>
<asp:textbox id="textBox" runat="server"></asp:textbox>
</itemtemplate></asp:templatefield>
</columns>
</asp:gridview>
文件后面的代码
Code Behind File
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Rows.Add("G");
dt.Rows.Add("K");
grid.DataSource = dt;
grid.DataBind();
}
protected void RowDataBoundEvent(object sender, GridViewRowEventArgs e)
{
int rowIndex = e.Row.RowIndex;
if (rowIndex >= 0)
{
((CheckBox)e.Row.FindControl("cbSelect")).Attributes.Add("onclick", "javascript:ToggleTextBox('" +
((CheckBox)e.Row.FindControl("cbSelect")).ClientID + "','"+
((TextBox)e.Row.FindControl("textBox")).ClientID + "')");
}
}