0

I'm having a ListView in grid format which comprises headers as (NAME,ID,ADDRESS,GENDER,MOBILENO,PHOTO,BLOCK).

The BLOCK column consists a CheckBox in each row.

When the checkbox is checked in the BLOCK column, that particular row of the checkbox should be changed to ReadOnly, resulting in change of that particular row's backcolor.

my listview coding in aspx is...

        <AlternatingItemTemplate>
            <tr  class="AITtr">

                <td>
                    <asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
                </td>
                <td>
                    <asp:Label ID="ADDRESSLabel" runat="server" Text='<%# Eval("ADDRESS") %>' />
                </td>
                <td>
                    <asp:Label ID="GENDERLabel" runat="server" Text='<%# Eval("GENDER") %>' />
                </td>
                <td>
                    <asp:Label ID="MOBILENOLabel" runat="server" Text='<%# Eval("MOBILENO") %>' />
                </td>
                <td>
                    <asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("PHOTO") %>' Height="30" Width="30" />
                </td>
                <td>
                    <asp:CheckBox ID="BLOCKCheckBox" runat="server"  Checked="false" Enabled="true" />
                </td>
                <td>
                   <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
                   <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
                </td>
            </tr>
        </AlternatingItemTemplate>

        <EditItemTemplate>
            <tr class="EITtr">

                <td>
                    <asp:TextBox ID="NAMETextBox" runat="server" Text='<%# Bind("NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
                </td>
                <td>
                    <asp:TextBox ID="ADDRESSTextBox" runat="server" Text='<%# Bind("ADDRESS") %>' />
                </td>
                <td>
                    <asp:TextBox ID="GENDERTextBox" runat="server" Text='<%# Bind("GENDER") %>' />
                </td>
                <td>
                    <asp:TextBox ID="MOBILENOTextBox" runat="server" Text='<%# Bind("MOBILENO") %>' />

                </td>
                <td>
                    <asp:TextBox ID="PHOTOTextBox" runat="server" Text='<%# Bind("PHOTO") %>' />
                </td>
                <td>
                    <asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true"   />
                </td>
                <td>
                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Update" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Cancel" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
                </td>
            </tr>
        </EditItemTemplate>

        <EmptyDataTemplate>
            <table runat="server" class="EDTtable" >
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>

        <InsertItemTemplate>
            <tr>

                <td>
                    <asp:TextBox ID="NAMETextBox" runat="server" Text='<%# Bind("NAME") %>' />
                </td>
                <td>
                    &nbsp;</td>
                <td>
                    <asp:TextBox ID="ADDRESSTextBox" runat="server" Text='<%# Bind("ADDRESS") %>' />
                </td>
                <td>
                    <asp:TextBox ID="GENDERTextBox" runat="server" Text='<%# Bind("GENDER") %>' />
                </td>
                <td>
                    <asp:TextBox ID="MOBILENOTextBox" runat="server" Text='<%# Bind("MOBILENO") %>' />
                </td>
                <td>
                    <asp:TextBox ID="PHOTOTextBox" runat="server" Text='<%# Bind("PHOTO") %>' />
                </td>
                <td>
                    <asp:CheckBox ID="BLOCKCheckBox" runat="server"  Checked="false" Enabled="true"  />
                </td>
                 <td>
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Insert" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
                    <asp:Button ID="CancelButton1" runat="server" CommandName="Cancel" 
                        Text="Clear" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
                </td>
            </tr>
        </InsertItemTemplate>

        <ItemTemplate>
            <tr class="ITtr">

                <td>
                    <asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
                </td>
                <td>
                    <asp:Label ID="ADDRESSLabel" runat="server" Text='<%# Eval("ADDRESS") %>' />
                </td>
                <td>
                    <asp:Label ID="GENDERLabel" runat="server" Text='<%# Eval("GENDER") %>' />
                </td>
                <td>
                    <asp:Label ID="MOBILENOLabel" runat="server" Text='<%# Eval("MOBILENO") %>' />
                </td>
                <td>
                    <asp:Image ID="Image" runat="server" ImageUrl='<%#Eval("PHOTO") %>' Height="30" Width="30" />
                </td>
                <td>
                    <asp:CheckBox ID="BLOCKCheckBox" runat="server"  Checked="false" Enabled="true" />
                </td>
                 <td>
                   <asp:Button ID="DeleteButton1" runat="server" CommandName="Delete" 
                        Text="Delete" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
                    <asp:Button ID="EditButton1" runat="server" CommandName="Edit" Text="Edit" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
                </td>
            </tr>
        </ItemTemplate>

        <LayoutTemplate>
            <table runat="server">
                <tr runat="server">
                    <td runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="1" class="LTtable" >

                      <tr runat="server" Class="LTtr">

                                <th runat="server">
                                    NAME</th>
                                <th runat="server">
                                    ID</th>
                                <th runat="server">
                                    ADDRESS</th>
                                <th runat="server">
                                    GENDER</th>
                                <th runat="server">
                                    MOBILENO</th>
                                <th runat="server">
                                    PHOTO</th>
                                <th runat="server">
                                    BLOCK</th>
                                <th id="Th1" runat="server">
                                </th>
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr runat="server">
                    <td runat="server" class="LTtd">
                    </td>
                </tr>
            </table>
        </LayoutTemplate>

        <SelectedItemTemplate>
            <tr Class=".SITtr">

                <td>
                    <asp:Label ID="NAMELabel" runat="server" Text='<%# Eval("NAME") %>' />
                </td>
                <td>
                    <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
                </td>
                <td>
                    <asp:Label ID="ADDRESSLabel" runat="server" Text='<%# Eval("ADDRESS") %>' />
                </td>
                <td>
                    <asp:Label ID="GENDERLabel" runat="server" Text='<%# Eval("GENDER") %>' />
                </td>
                <td>
                    <asp:Label ID="MOBILENOLabel" runat="server" Text='<%# Eval("MOBILENO") %>' />
                </td>
                 <td>
                     <asp:Label ID="PHOTOLabel" runat="server" Text='<%# Eval("PHOTO") %>' />
                </td>
                 <td>
                    <asp:CheckBox ID="BLOCKCheckBox" runat="server" Checked="false" Enabled="true"  />
                </td>
                <td>
                    <asp:Button ID="DeleteButton2" runat="server" CommandName="Delete" 
                        Text="Delete" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light" />
                    <asp:Button ID="EditButton2" runat="server" CommandName="Edit" Text="Edit" BackColor="#577109" ForeColor="Black" BorderStyle="Solid" Font-Names="Copperplate Gothic Light"/>
                </td>
            </tr>
        </SelectedItemTemplate>

    </asp:ListView>

my aspx.cs coding is....

 protected void ListView1_OnItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            CheckBox BLOCKCheckBox = (e.Item.FindControl("BLOCKCheckBox") as CheckBox);
            if (BLOCKCheckBox.Checked)
            {

            }
            else
            {

            }

        }
    }

Kindly help me.....

Thanks....

3
  • The part of logic u wish to implement should be done via JavaScript, not C#, or with Ajax requests (also JS), or probably with full reload of page (pure .asp) . I think you need to read more about subject. Commented Feb 5, 2015 at 7:02
  • change in the back color of the row is not important, Commented Feb 5, 2015 at 7:05
  • it should change to read only mode Commented Feb 5, 2015 at 7:05

1 Answer 1

1

add oncheckedChanged for block check box and autopostback=true

aspx.cs

 protected void BLOCKCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox checkbox = (CheckBox)sender;
        ListViewItem itm = (ListViewItem)checkbox.NamingContainer;
        if (lstview1.EditIndex == itm.DisplayIndex)
        {

            (itm.FindControl("NAMETextBox") as TextBox).ReadOnly = true;
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.