我正在使用带有复选框和两个文本框的gridview。我想要做的是,一旦焦点在网格视图中的文本框上,就会自动选中复选框。有人可以帮我这个吗?
<asp:GridView ID="dglist" runat="server" AutoGenerateColumns="False" EditRowStyle-
Wrap="true" Font-Size="9px" Width="500px"
EmptyDataText="Empty" OnRowDataBound="dglist_RowDataBound"
OnRowCommand="dglist_RowCommand" OnRowEditing="dglist_RowEditing">
<HeaderStyle Width="1%" CssClass="Gridheader" />
<RowStyle ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkSelect" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TextBox1">
<ItemTemplate>
<asp:Texbox runat="server" ID="txtBox1" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TextBox2">
<ItemTemplate>
<asp:Texbox runat="server" ID="txtBox2" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
谢谢, 苏
答案 0 :(得分:0)
试试这个javascript
function check()
{
var chk=document.getElementId("chkSelect");
chk.checked=true;
}
<asp:TemplateField HeaderText="TextBox1" onFocus="check();"><ItemTemplate>
答案 1 :(得分:0)
<asp:gridview ID="grdCustomer" runat="server">
<Columns>
<asp:TemplateField>
<itemtemplate>
<asp:checkbox ID="chkSelect" runat="server" />Check
</itemtemplate>
</asp:TemplateField>
<asp:templatefield>
<itemtemplate>
<asp:textbox ID="txtData" runat="server" onfocus="Check(this);">
</asp:textbox>
</itemtemplate>
</asp:templatefield>
</Columns>
</asp:gridview>
<script type="text/javascript">
function Check(lnk) {
var dataGrid = document.all['grdCustomer'];
var row = lnk.parentNode.parentNode;
var checkBox = dataGrid.rows[row.rowIndex].cells[0].childNodes[0];
checkBox.checked = true;
}
</script>