Gridview复选框和文本框的生成 [英] Gridview Checkbox and textbox generation
本文介绍了Gridview复选框和文本框的生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有GridView.这样,我将按照我的数据库值行显示行.
我只想在第二列中添加复选框,在最后一列中添加一个文本框.
同样,在页面加载时,最后一列的文本框值应该是只读的.
当我单击复选框时,则仅应启用它.
该怎么做...?
看我的代码..
Hi,
I have GridView. In that, i am displaying rows as per my DB Value rows.
I just want to add in second column checkbox and last column one textbox.
Also, page load, the last column textbox values should be read only.
When i click check box, then only it should enable.
How to do that...?
see my code..
<asp:GridView ID="GridView1" runat="server" align="center" AllowPaging="True"
AutoGenerateColumns="False" class="tabulardata" DataSourceID="SqlDataSource1"
HorizontalAlign="Center" Width="100%" OnRowCommand="GridView1_RowCommand"
OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" OnRowDeleting="GridView1_RowDeleting">
<columns>
<asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center"
ItemStyle-Width="4%">
<itemtemplate>
<asp:Label ID="Sno" runat="server">
</itemtemplate>
<itemstyle horizontalalign="Center" />
<asp:TemplateField HeaderText="Active">
<edititemtemplate>
<asp:CheckBox ID="chkActive" runat="server" />
</edititemtemplate>
<itemtemplate>
<asp:Label ID="lblActive" runat="server" Text="">
</itemtemplate>
<footertemplate>
<asp:CheckBox ID="chkNewActive" runat="server" />
</footertemplate>
<asp:BoundField HeaderText="Department" Visible="true" DataField="Department"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="Department">
<itemstyle horizontalalign="Center" width="20%" />
<asp:BoundField HeaderText="Cost Centre" Visible="true" DataField="CostCentre"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="CostCentre">
<itemstyle horizontalalign="Center" width="20%" />
<asp:BoundField HeaderText="Work Service Code" DataField="WorkServiceCode"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="WorkServiceCode">
<itemstyle horizontalalign="Center" width="30%" />
<asp:BoundField HeaderText="Prof.Role Family ID" DataField="ProfRoleFamilyID"
ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="ProfRoleFamilyID">
<itemstyle horizontalalign="Center" width="28%" />
</columns>
<alternatingrowstyle backcolor="#FFF5F5" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ConnectionStrings:MPP%>"
SelectCommand="select Department,CostCentre,WorkServiceCode,ProfRoleFamilyID from mppProjBudgetChart">
推荐答案
ConnectionStrings:MPP %> " SelectCommand =" span> >
ConnectionStrings:MPP%>" SelectCommand="select Department,CostCentre,WorkServiceCode,ProfRoleFamilyID from mppProjBudgetChart">
1)您的复选框应具有on_click事件
2)在这种情况下,您可以使用发送方对象来查找在网格视图的哪一行中单击了复选框.
1) your checkbox should have on_click event
2) in that event you can use the sender Object to find in which row of the gridview the checkbox was clicked.
<br />
protected void CheckBox1_OnClicked(object sender, EventArgs e)<br />
{<br />
CheckBox chkBX = (CheckBox)sender;<br />
GridViewRow row = (GridViewRow)chkBX.NamingContainer;<br />
TextBox myTextBox = row.FindControl("nameOfTextBoxControl");<br />
if (null != myTextBox)<br />
myTextBox.Enabled = chkBX.Checked;<br />
}<br />
这篇关于Gridview复选框和文本框的生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文