网格视图中的复选框不可选 [英] Check box within grid view is not selectable
本文介绍了网格视图中的复选框不可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下所示,我的问题是,当我在Visual Studio中使用此代码时,它将无法正常工作。 (我在办公室使用过这个,但没有工作)
实际问题是,当我尝试选中复选框时,无法选择它。
自动回复是真的。
My code is as below and my problem is that when I used this code in Visual Studio
2008 it will not work properly. (I used this in my office, but not working)
Actually problem is that when I try to select the check box it cannot be selected.
Auto post back is true.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CC9966" BorderWidth="1px"
CellPadding="4" DataKeyNames="Eid,Fname"
onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating"
onselectedindexchanged="GridView1_SelectedIndexChanged" ShowFooter="True"
style="z-index: 1; left: 126px; top: 262px; position: absolute; height: 140px; width: 448px"
onrowcommand="GridView1_RowCommand" AllowSorting="True"
onpageindexchanging="GridView1_PageIndexChanging" onsorting="GridView1_Sorting"
PageSize="2" AllowPaging="True" BorderStyle="None">
<pagersettings firstpagetext="First" lastpagetext="Last" nextpagetext="Next">
PreviousPageText="Prev" />
<footerstyle backcolor="#FFFFCC" forecolor="#330099" />
<columns>
<asp:TemplateField HeaderText="Eid" SortExpression="Eid">
<edititemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("EId") %>'>
</edititemtemplate>
<footertemplate>
<asp:TextBox ID="TextBox4" runat="server"
>
</footertemplate>
<itemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("EId") %>'>
</itemtemplate>
<asp:TemplateField HeaderText="Salary" SortExpression="Salary">
<edititemtemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Salary") %>'>
</edititemtemplate>
<footertemplate>
<asp:TextBox ID="TextBox5" runat="server"
>
</footertemplate>
<itemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Salary") %>'>
</itemtemplate>
<asp:TemplateField HeaderText="Name" SortExpression="Name">
<edititemtemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
SelectedValue='<%# Eval("FName") %>'
DataSourceID="SqlDataSource1" DataTextField="Fname" DataValueField="Fname">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"
SelectCommand="SELECT [Fname] FROM [Employee]">
</edititemtemplate>
<footertemplate>
<asp:TextBox ID="TextBox6" runat="server"
>
</footertemplate>
<itemtemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("FName") %>'>
</itemtemplate>
<%--<asp:CheckBoxField DataField="IsTemp" />--%>
<asp:TemplateField HeaderText="Edit" ShowHeader="False">
<edititemtemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True"
CommandName="Update" Text="Update">
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel">
</edititemtemplate>
<footertemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Insert">Insert
</footertemplate>
<itemtemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit">
</itemtemplate>
<asp:CommandField ShowDeleteButton="True" />
<asp:CommandField ShowSelectButton="True" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox2_CheckedChanged"/>
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="showtxtbox" Checked="False" Enabled="True" EnableViewState="True" ViewStateMode="Inherit" /><asp:TextBox ID="TextBox7" runat="server" Visible="false">
</itemtemplate>
<asp:HyperLinkField DataNavigateUrlFields="Salary"
DataNavigateUrlFormatString="Default2.aspx?sal={0}" DataTextField="FName" />
<asp:ButtonField ButtonType="Button" DataTextField="Salary" Text="Button" />
<asp:TemplateField HeaderText="txtvalue" SortExpression="txtvalue">
<edititemtemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Eval("txtvalue") %>'>
</edititemtemplate>
<itemtemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("txtvalue") %>'>
</itemtemplate>
</columns>
<pagerstyle backcolor="#FFFFCC" forecolor="#330099">
HorizontalAlign="Center" />
<rowstyle backcolor="White" forecolor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" ForeColor="#663399" Font-Bold="True" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<sortedascendingcellstyle backcolor="#FEFCEB" />
<sortedascendingheaderstyle backcolor="#AF0101" />
<sorteddescendingcellstyle backcolor="#F6F0C0" />
<sorteddescendingheaderstyle backcolor="#7E0000" />
My cs file code is:
My cs file code is:
protected void showtxtbox(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
GridViewRow gvr=(GridViewRow) cb.NamingContainer;
int rrowindex = gvr.RowIndex;
CheckBox cbb = (CheckBox)GridView1.Rows[rrowindex].Cells[6].Controls[1];
TextBox txt=(TextBox)GridView1.Rows[rrowindex].Cells[6].Controls[2];
cbb.Checked=cb.Checked;
if (cbb.Checked)
{
txt.Visible = true;
}
if (cbb.Checked == false)
{
txt.Visible = false;
}
}
推荐答案
ConnectionStrings:masterConnectionString %>\"
SelectCommand=\"SELECT [Fname] FROM [Employee]\">
</edititemtemplate>
<footertemplate>
<asp:TextBox ID=\"TextBox6\" runat=\"server\"
>
</footertemplate>
<itemtemplate>
<asp:Label ID=\"Label3\" runat=\"server\" Text='<%# Bind(\"FName\") %>'>
</itemtemplate>
<%--<asp:CheckBoxField DataField=\"IsTemp\" />--%>
<asp:TemplateFieldHeaderText=\"Edit\" ShowHeader=\"False\"> oncheckedchanged=\"CheckBox2_CheckedChanged\"/>
<edititemtemplate>
<asp:LinkButton ID=\"LinkButton1\" runat=\"server\" CausesValidation=\"True\"
CommandName=\"Update\" Text=\"Update\">
<asp:LinkButton ID=\"LinkButton2\" runat=\"server\" CausesValidation=\"False\"
CommandName=\"Cancel\" Text=\"Cancel\">
</edititemtemplate>
<footertemplate>
< span class=\"code-keyword\"><asp:LinkButton ID=\"LinkButton3\" runat=\"server\" CommandName=\"Insert\">Insert
</footertemplate>
<itemtemplate>
<asp:LinkButton ID=\"LinkButton1\" runat=\"server\" CausesValidation=\"False\"
CommandName=\"Edit\" Text=\"Edit\">
</itemtemplate>
<asp:CommandField ShowDeleteButton=\"True\" />
<asp:CommandField ShowSelectButton=\"True\" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID=\"CheckBox2\" runat=\"server\" AutoPostBack=\"True\"
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox ID=\"CheckBox1\" runat=\"server\" AutoPostBack=\"True\" OnCheckedChanged=\"showtxtbox\" Checked=\"False\" Enabled=\"True\" EnableViewState=\"True\" ViewStateMode=\"Inherit\" /><asp:TextBox ID=\"TextBox7\" runat=\"server\" Visible=\"false\">
</itemtemplate>
<asp:HyperLinkField DataNavigateUrlFields=\"Salary\"
DataNavigateUrlFormatString =\"Default2.aspx?sal={0}\" DataTextField=\"FName\" />
<asp:ButtonField ButtonType=\"Button\" DataTextField=\"Salary\" Text=\"Button\" />
<asp:TemplateField HeaderText=\"txtvalue\" SortExpression=\"txtvalue\">
<edititemtemplate>
<asp:Label ID=\"Label12\" runat=\"server\" Text='<%# Eval(\"txtvalue\") %>'>
</edititemtemplate>
<itemtemplate>
<asp:Label ID=\"Label12\" runat=\"server\" Text='<%# Bind(\"txtvalue\") %>'>
</itemtemplate>
</columns>
<pagerstyle backcolor=\"#FFFFCC\" forecolor=\"#330099\">
HorizontalAlign=\"Center\" />
<rowstyle backcolor=\"White\" forecolor=\"#330099\" />
<SelectedRowStyle BackColor=\"#FFCC66\" ForeColor=\"#663399\" Font-Bold=\"True\" />
<HeaderStyle BackColor=\"#990000\" Font-Bold=\"True\" ForeColor=\"#FFFFCC\" />
<sortedascendingcellstyle backcolor=\"#FEFCEB\" />
<sortedascendingheaderstyle backcolor=\"#AF0101\" />
<sorteddescendingcellstyle backcolor=\"#F6F0C0\" />
<sorteddescendingheaderstyle backcolor=\"#7E0000\" />
ConnectionStrings:masterConnectionString %>" SelectCommand="SELECT [Fname] FROM [Employee]"> </edititemtemplate> <footertemplate> <asp:TextBox ID="TextBox6" runat="server" > </footertemplate> <itemtemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("FName") %>'> </itemtemplate> <%--<asp:CheckBoxField DataField="IsTemp" />--%> <asp:TemplateField HeaderText="Edit" ShowHeader="False"> <edititemtemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </edititemtemplate> <footertemplate> <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Insert">Insert </footertemplate> <itemtemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"> </itemtemplate> <asp:CommandField ShowDeleteButton="True" /> <asp:CommandField ShowSelectButton="True" /> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox2_CheckedChanged"/> </HeaderTemplate> <itemtemplate> <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="showtxtbox" Checked="False" Enabled="True" EnableViewState="True" ViewStateMode="Inherit" /><asp:TextBox ID="TextBox7" runat="server" Visible="false"> </itemtemplate> <asp:HyperLinkField DataNavigateUrlFields="Salary" DataNavigateUrlFormatString="Default2.aspx?sal={0}" DataTextField="FName" /> <asp:ButtonField ButtonType="Button" DataTextField="Salary" Text="Button" /> <asp:TemplateField HeaderText="txtvalue" SortExpression="txtvalue"> <edititemtemplate> <asp:Label ID="Label12" runat="server" Text='<%# Eval("txtvalue") %>'> </edititemtemplate> <itemtemplate> <asp:Label ID="Label12" runat="server" Text='<%# Bind("txtvalue") %>'> </itemtemplate> </columns> <pagerstyle backcolor="#FFFFCC" forecolor="#330099"> HorizontalAlign="Center" /> <rowstyle backcolor="White" forecolor="#330099" /> <SelectedRowStyle BackColor="#FFCC66" ForeColor="#663399" Font-Bold="True" /> <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /> <sortedascendingcellstyle backcolor="#FEFCEB" /> <sortedascendingheaderstyle backcolor="#AF0101" /> <sorteddescendingcellstyle backcolor="#F6F0C0" /> <sorteddescendingheaderstyle backcolor="#7E0000" />
My cs file code is:
My cs file code is:
protected void showtxtbox(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
GridViewRow gvr=(GridViewRow) cb.NamingContainer;
int rrowindex = gvr.RowIndex;
CheckBox cbb = (CheckBox)GridView1.Rows[rrowindex].Cells[6].Controls[1];
TextBox txt=(TextBox)GridView1.Rows[rrowindex].Cells[6].Controls[2];
cbb.Checked=cb.Checked;
if (cbb.Checked)
{
txt.Visible = true;
}
if (cbb.Checked == false)
{
txt.Visible = false;
}
}
so if you have a checkbox for each row of the grid using template field, and upon checking the checkbox you want to show a textbox as visible? try this solution below, you can convert it to c#.
so if you have a checkbox for each row of the grid using template field, and upon checking the checkbox you want to show a textbox as visible? try this solution below, you can convert it to c#.
For Each row As GridViewRow In GridView.Rows
Dim cbb As CheckBox = DirectCast(row.FindControl("CheckBox1"), CheckBox)
Dim txt As Textbox = DirectCast(row.FindControl("textbox1"), textbox)
If checkbox.Checked Then
Dim rowid As Integer = Convert.ToInt32(GridView.DataKeys(row.RowIndex).Value)
If cbb.Checked = False Then
txt.Visible = False
End If
Next
这篇关于网格视图中的复选框不可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文