Click here to Skip to main content

GDdixit asked:

Open original thread
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" 
 
<pre>
        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"&gt;
        &lt;pagersettings firstpagetext="First" lastpagetext="Last" nextpagetext="Next"&gt;
            PreviousPageText="Prev" /&gt;
        &lt;footerstyle backcolor="#FFFFCC" forecolor="#330099" /&gt;
        &lt;columns&gt;
            &lt;asp:TemplateField HeaderText="Eid" SortExpression="Eid"&gt;
                &lt;edititemtemplate&gt;
                    &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("EId") %&gt;'&gt;
                &lt;/edititemtemplate&gt;
                &lt;footertemplate&gt;
                    &lt;asp:TextBox ID="TextBox4" runat="server" 
                       &gt;
                &lt;/footertemplate&gt;
                &lt;itemtemplate&gt;
                    &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("EId") %&gt;'&gt;
                &lt;/itemtemplate&gt;
 
            &lt;asp:TemplateField HeaderText="Salary" SortExpression="Salary"&gt;
                &lt;edititemtemplate&gt;
                    &lt;asp:TextBox ID="TextBox1" runat="server" Text='&lt;%# Bind("Salary") %&gt;'&gt;
                &lt;/edititemtemplate&gt;
                &lt;footertemplate&gt;
                    &lt;asp:TextBox ID="TextBox5" runat="server" 
                       &gt;
                &lt;/footertemplate&gt;
                &lt;itemtemplate&gt;
                    &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("Salary") %&gt;'&gt;
                &lt;/itemtemplate&gt;
 
            &lt;asp:TemplateField HeaderText="Name" SortExpression="Name"&gt;
                &lt;edititemtemplate&gt;
                    &lt;asp:DropDownList ID="DropDownList1" runat="server" 
                        SelectedValue='&lt;%# Eval("FName") %&gt;' 
                        DataSourceID="SqlDataSource1" DataTextField="Fname" DataValueField="Fname"&gt;
 
                    &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                        ConnectionString="&lt;%$ ConnectionStrings:masterConnectionString %&gt;" 
                        SelectCommand="SELECT [Fname] FROM [Employee]"&gt;
                &lt;/edititemtemplate&gt;
                &lt;footertemplate&gt;
                    &lt;asp:TextBox ID="TextBox6" runat="server" 
                        &gt;
                &lt;/footertemplate&gt;
                &lt;itemtemplate&gt;
                    &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("FName") %&gt;'&gt;
                &lt;/itemtemplate&gt;
 
            &lt;%--&lt;asp:CheckBoxField DataField="IsTemp" /&gt;--%&gt;
            &lt;asp:TemplateField HeaderText="Edit" ShowHeader="False"&gt;
                &lt;edititemtemplate&gt;
                    &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text="Update"&gt;
                    &nbsp;&lt;asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel"&gt;
                &lt;/edititemtemplate&gt;
                &lt;footertemplate&gt;
                    &lt;asp:LinkButton ID="LinkButton3" runat="server" CommandName="Insert"&gt;Insert
                &lt;/footertemplate&gt;
                &lt;itemtemplate&gt;
                    &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Edit"&gt;
                &lt;/itemtemplate&gt;
 
            &lt;asp:CommandField ShowDeleteButton="True" /&gt;
            &lt;asp:CommandField ShowSelectButton="True" /&gt;
            &lt;asp:TemplateField&gt;
                &lt;HeaderTemplate&gt;
                    &lt;asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" 
                        oncheckedchanged="CheckBox2_CheckedChanged"/&gt;
                &lt;/HeaderTemplate&gt;
                &lt;itemtemplate&gt;
                    &lt;asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"  OnCheckedChanged="showtxtbox" Checked="False" Enabled="True" EnableViewState="True" ViewStateMode="Inherit" /&gt;&lt;asp:TextBox ID="TextBox7" runat="server" Visible="false"&gt;
                &lt;/itemtemplate&gt;
 
            &lt;asp:HyperLinkField DataNavigateUrlFields="Salary" 
                DataNavigateUrlFormatString="Default2.aspx?sal={0}" DataTextField="FName" /&gt;
            &lt;asp:ButtonField ButtonType="Button" DataTextField="Salary" Text="Button" /&gt;
            &lt;asp:TemplateField HeaderText="txtvalue" SortExpression="txtvalue"&gt;
                &lt;edititemtemplate&gt;
                    &lt;asp:Label ID="Label12" runat="server" Text='&lt;%# Eval("txtvalue") %&gt;'&gt;
                &lt;/edititemtemplate&gt;
 
                &lt;itemtemplate&gt;
                    &lt;asp:Label ID="Label12" runat="server" Text='&lt;%# Bind("txtvalue") %&gt;'&gt;
                &lt;/itemtemplate&gt;
 
        &lt;/columns&gt;
 
        &lt;pagerstyle backcolor="#FFFFCC" forecolor="#330099"&gt;
            HorizontalAlign="Center" /&gt;
        &lt;rowstyle backcolor="White" forecolor="#330099" /&gt;
        &lt;SelectedRowStyle BackColor="#FFCC66" ForeColor="#663399" Font-Bold="True" /&gt;
        &lt;HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" /&gt;
        &lt;sortedascendingcellstyle backcolor="#FEFCEB" /&gt;
        &lt;sortedascendingheaderstyle backcolor="#AF0101" /&gt;
        &lt;sorteddescendingcellstyle backcolor="#F6F0C0" /&gt;
        &lt;sorteddescendingheaderstyle backcolor="#7E0000" /&gt;</pre>

My cs file code is:
protected void showtxtbox(object sender, EventArgs e)
    {
 
<pre>
    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;
        }
 
}</pre>
Tags: ASP.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100