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 6730829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:27:21+00:00 2026-05-26T10:27:21+00:00

After Filling a DataTable in GridView’s DataSource . A column with check box Type

  • 0

After Filling a DataTable in GridView’s DataSource . A column with check box Type appears but it created as read only column
and I can’t enable it or make it editable… even i tried .readonly = false
and still can’t be edited
can any one help please ?

  • 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-05-26T10:27:22+00:00Added an answer on May 26, 2026 at 10:27 am

    you can try like this..

    This is by design; rows in a GridView are not editable by default.

    There’s two ways you might address this:

    1. Add an Edit link
      In your GridView tag, add AutoGenerateEditButton="True". When your GridView renders in the browser, you should now find a hyperlink labelled ‘Edit’. If you click it, the fields in your GridView will become editable, and the Edit link will become two links, one to save your changes to the database and the other to discard them. Using this method, all the plumbing to wire up changes in the GridView to the database can be done for you, depending on how you’re doing the databinding. This example uses a SqlDataSource control.
      alt text
      (source: philippursglove.com)

    alt text

    1. Add a TemplateField with a CheckBox inside it
      Inside the <columns> tag, you can add TemplateFields that you set the databinding up for yourself e.g.

      <asp:TemplateField HeaderText="Discontinued">
      <ItemTemplate>
      <asp:CheckBox runat="server" ID="DiscontinuedCheckBox" Checked="<%# Eval("Discontinued") %>" AutoPostback="true" OnCheckedChanged="DiscontinuedCheckBox_CheckedChanged" />
      </ItemTemplate>
      </asp:TemplateField>

    alt text
    (source: philippursglove.com)

    This checkbox will be enabled, but you need to do the work yourself to reflect any changes back to the database. This is straightforward as long as you can get a database key, as you’ll need to run an UPDATE statement at some point and you want to run it on the right row! Here’s two ways you could do this:

    In your Gridview tag, add DataKeyNames="MyDatabasePrimaryKey". Then in your CheckedChanged event handler, you need to find out which row you are in and look that up in the DataKeys array.

       Protected Sub DiscontinuedCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim DiscontinuedCheckBox As CheckBox
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim productId As Integer
        Dim selectedRow As GridViewRow
        ' Cast the sender object to a CheckBox
        DiscontinuedCheckBox = CType(sender,CheckBox)
        ' We can find the row we clicked the checkbox in by walking up the control tree
        selectedRow = CType(DiscontinuedCheckBox.Parent.Parent,GridViewRow)
        ' GridViewRow has a DataItemIndex property which we can use to look up the DataKeys array
        productId = CType(ProductGridView.DataKeys(selectedRow.DataItemIndex).Value,Integer)
        conn = New SqlConnection(ProductDataSource.ConnectionString)
        cmd = New SqlCommand
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        If DiscontinuedCheckBox.Checked Then
            cmd.CommandText = ("UPDATE Products SET Discontinued = 1 WHERE ProductId = " + ProductId.ToString)
        Else
            cmd.CommandText = ("UPDATE Products SET Discontinued = 0 WHERE ProductId = " + ProductId.ToString)
        End If
        conn.Open
        cmd.ExecuteNonQuery
        conn.Close
    End Sub
    

    Or, you could add the key in a HiddenField control:

    <asp:TemplateField HeaderText="Discontinued">
    <ItemTemplate>
    <asp:hiddenfield runat="server" id="ProductIdHiddenField" Value='<%# Eval("ProductID") %>' />
    <asp:CheckBox runat="server" ID="DiscontinuedCheckBox" Checked="<%# Eval("Discontinued") %>" AutoPostback="true" OnCheckedChanged="DiscontinuedCheckBox_CheckedChanged" />
    </ItemTemplate>
    </asp:TemplateField>

         Protected Sub DiscontinuedCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim DiscontinuedCheckBox As CheckBox
        Dim ProductIdHiddenField As HiddenField
        DiscontinuedCheckBox = CType(sender,CheckBox)
        ProductIdHiddenField = CType(DiscontinuedCheckBox.Parent.FindControl("ProductIdHiddenField"),HiddenField)
        conn = New SqlConnection(ProductDataSource.ConnectionString)
     ..................
        If DiscontinuedCheckBox.Checked Then
            cmd.CommandText = ("UPDATE Products SET Discontinued = 1 WHERE ProductId = " + ProductIdHiddenField.Value)
        End If
    ...............
    End Sub
    

    i hope it will helps you….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose my datatable is filled with data. After filling data can we again put
How can I check if the user is closing the window after filling in
After hours of debugging, it appears to me that in FireFox, the innerHTML of
I'm currently dealing with customs messages Beans in Java. After filling in the Beans
I have a form. When a user submits the form after filling it, I
I've a php web page with a form. After filling the form in web
I'm writing an integration test for a rails application using webrat. After filling out
I have following procedure which is filling up null values in a column. The
I have created a controllers called user_controller in my cakephp app. After I've run
I have a site that directs a user to a php page, after filling

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.