Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:31:31+00:00 2026-06-13T17:31:31+00:00

I want to update data when I checked in gridview. Before I shoude get

  • 0

I want to update data when I checked in gridview. Before I shoude get value from checkbox but my code return data from database only. I want current value after I checked.

CodeBehind:-

protected void chkSelected_CheckedChanged(object sender, EventArgs e)
{
    for (int rowIndex = 0; rowIndex < GridView1.Rows.Count; rowIndex++)
    {
        if (Convert.ToString(GridView1.Rows[rowIndex].Cells[4].Text) != "")
        {
            Response.Write("true");
        }
        else
        {
            Response.Write("fasle");
        }
    }
}

Design Code:-

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
              CellPadding="4" GridLines="None" ForeColor="#333333" Font-Size="Smaller" 
              AutoGenerateColumns="False">
    <RowStyle BackColor="#EFF3FB" />
    <Columns>
        <asp:BoundField DataField="LevelID" HeaderText="ลำดับข้อ" ReadOnly="True" 
                        ItemStyle-Width="50"  >
        </asp:BoundField>
        <asp:BoundField DataField="LevelDesc" HeaderText="คำถาม" ReadOnly="True" 
                        ItemStyle-Width="250"  >
        </asp:BoundField>
        <asp:BoundField DataField="ChoiceID" HeaderText="ข้อย่อย" ReadOnly="True" 
                        ItemStyle-Width="50"  >
        </asp:BoundField>
        <asp:BoundField DataField="ChoiceDesc" HeaderText="คำถามย่อย" ReadOnly="True" 
                        ItemStyle-Width="400"  >
        </asp:BoundField>
        <asp:TemplateField HeaderText="ใช่">          
            <ItemTemplate>              
                <asp:CheckBox ID="chkSelected" runat="server" Checked='<%# Eval("Selected").ToString().Equals("True") %>'
                     AutoPostBack="true" OnCheckedChanged="chkSelected_CheckedChanged" CssClass="chkBox" />          
            </ItemTemplate>       
        </asp:TemplateField> 
    </Columns>
    <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle BackColor="#0000CD" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
</asp:GridView>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:31:32+00:00Added an answer on June 13, 2026 at 5:31 pm

    use GridViewRow as follow…You can get the current row of the checkbox which is checked using NamingContainer property as follow…

    Edit:-
    Change the markup and add Hiddenfield to hold value for Selected as follow…

    <asp:TemplateField HeaderText="ใช่">          
                <ItemTemplate>              
                    <asp:CheckBox ID="chkSelected" runat="server"  Checked='<%# Eval("Selected").ToString().Equals("True") %>'
                         AutoPostBack="true" OnCheckedChanged="chkSelected_CheckedChanged" CssClass="chkBox" />     
                    <asp:HiddenField ID="hiddenField1" Value='<%# Eval("Selected").ToString() %>' runat="server" />    
                </ItemTemplate>       
     </asp:TemplateField> 
    

    Then you can get the Hiddenfield as follow and it’s value as well

    protected void chkSelected_CheckedChanged(object sender, EventArgs e)
        {
             GridViewRow row = (GridViewRow)(((CheckBox)sender).NamingContainer);
             HiddenField hdnCheck=(HiddenField)row.Cells[4].FindControl("hiddenField1");
             if (Convert.ToString(hdnCheck.Value != "")
               {
                   Response.Write("true");
               }
               else
               {
                   Response.Write("false");
               }
    
             // Edit: You can easily get Checkbox which has been checked, and do your logic
             CheckBox chkSelect=(CheckBox)sender;
             if (chkSelect.Checked)
               {
                   Response.Write("true");
               }
               else
               {
                   Response.Write("false");
               }    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My customer doesn't want a database but would prefer to update their data in
I want to update the lastlogin column value .i wrote the code like this
i have ios application with xcdatamodeld, i want update some data so need a
I want to update my PHP GUI view when my data source is updated(data
What I want: Update all new commits from server with my local repository in
I want to update an erb.html page in rails with information from a webscraping
First off, im using a checkbox to highlight a true or false value from
Currently we have a table with a bunch of data from a database which
I want to merge data into a MySQL table from PHP : <?php function
As you can see from the title I basically want to update a plist.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.