Checkbox in a Gridview

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?=

    #1

    Checkbox in a Gridview

    Hi all,

    I have been playing with the check box in my gridview. When a user clicks
    on this box I just want it to do the following: textbox1.text = "Hello"

    I have played with the rowdatabound event but this event occurs when before
    the gridview is populated. I also tried the selectindex changed event when I
    had the select field invisible. Still no luck with either events.

    Can anyone help,
    Michael
  • Walter Wang [MSFT]

    #2
    RE: Checkbox in a Gridview

    Hi Michael,

    I'm not sure if I fully understand your question. But here's my try anyway:

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

    <script runat="server">

    protected void Page_Load(objec t sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    BindData();
    }
    }

    private void BindData()
    {
    grid1.DataSourc e = new int[5];
    grid1.DataBind( );
    }

    protected void check1_CheckedC hanged(object sender, EventArgs e)
    {
    text1.Text = "Hello";
    }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitl ed Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="text1" runat="server"> </asp:TextBox>
    <asp:GridView ID="grid1" runat="server">
    <Columns>
    <asp:TemplateFi eld>
    <ItemTemplate >
    <asp:CheckBox ID="check1" runat="server"
    AutoPostBack="t rue" Text="Check me"
    OnCheckedChange d="check1_Check edChanged" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
    </div>
    </form>
    </body>
    </html>


    Let me know if this is not what you wanted.

    Regards,
    Walter Wang (wawang@online. microsoft.com, remove 'online.')
    Microsoft Online Community Support

    =============== =============== =============== =====
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    =============== =============== =============== =====

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?=

      #3
      RE: Checkbox in a Gridview

      This would work but would you have a vb code sample?

      "Walter Wang [MSFT]" wrote:
      Hi Michael,
      >
      I'm not sure if I fully understand your question. But here's my try anyway:
      >
      <%@ Page Language="C#" %>
      >
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
      >
      <script runat="server">
      >
      protected void Page_Load(objec t sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      BindData();
      }
      }
      >
      private void BindData()
      {
      grid1.DataSourc e = new int[5];
      grid1.DataBind( );
      }
      >
      protected void check1_CheckedC hanged(object sender, EventArgs e)
      {
      text1.Text = "Hello";
      }
      >
      </script>
      >
      <html xmlns="http://www.w3.org/1999/xhtml" >
      <head runat="server">
      <title>Untitl ed Page</title>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>
      <asp:TextBox ID="text1" runat="server"> </asp:TextBox>
      <asp:GridView ID="grid1" runat="server">
      <Columns>
      <asp:TemplateFi eld>
      <ItemTemplate >
      <asp:CheckBox ID="check1" runat="server"
      AutoPostBack="t rue" Text="Check me"
      OnCheckedChange d="check1_Check edChanged" />
      </ItemTemplate>
      </asp:TemplateFie ld>
      </Columns>
      </asp:GridView>
      </div>
      </form>
      </body>
      </html>
      >
      >
      Let me know if this is not what you wanted.
      >
      Regards,
      Walter Wang (wawang@online. microsoft.com, remove 'online.')
      Microsoft Online Community Support
      >
      =============== =============== =============== =====
      When responding to posts, please "Reply to Group" via your newsreader so
      that others may learn and benefit from your issue.
      =============== =============== =============== =====
      >
      This posting is provided "AS IS" with no warranties, and confers no rights.
      >
      >

      Comment

      • Walter Wang [MSFT]

        #4
        RE: Checkbox in a Gridview

        Sure. Here's the VB.NET version:

        <%@ Page Language="VB" %>

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

        <script runat="server">

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As
        System.EventArg s)
        If Not IsPostBack Then
        BindData()
        End If
        End Sub

        Private Sub BindData()
        grid1.DataSourc e = New Integer(5) {}
        grid1.DataBind( )
        End Sub

        Protected Sub check1_CheckedC hanged(ByVal sender As Object, ByVal e As
        EventArgs)
        text1.Text = "Hello"
        End Sub
        </script>

        <html xmlns="http://www.w3.org/1999/xhtml" >
        <head runat="server">
        <title>Untitl ed Page</title>
        </head>
        <body>
        <form id="form1" runat="server">
        <div>
        <asp:TextBox ID="text1" runat="server"> </asp:TextBox>
        <asp:GridView ID="grid1" runat="server">
        <Columns>
        <asp:TemplateFi eld>
        <ItemTemplate >
        <asp:CheckBox ID="check1" runat="server"
        AutoPostBack="t rue" Text="Check me"
        OnCheckedChange d="check1_Check edChanged" />
        </ItemTemplate>
        </asp:TemplateFie ld>
        </Columns>
        </asp:GridView>

        </div>
        </form>
        </body>
        </html>


        Let me know if this works for you.

        Regards,
        Walter Wang (wawang@online. microsoft.com, remove 'online.')
        Microsoft Online Community Support

        =============== =============== =============== =====
        When responding to posts, please "Reply to Group" via your newsreader so
        that others may learn and benefit from your issue.
        =============== =============== =============== =====

        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • Walter Wang [MSFT]

          #5
          RE: Checkbox in a Gridview

          Hi Michael,

          How about this VB.NET version? Does that answer your question?

          Regards,
          Walter Wang (wawang@online. microsoft.com, remove 'online.')
          Microsoft Online Community Support

          =============== =============== =============== =====
          When responding to posts, please "Reply to Group" via your newsreader so
          that others may learn and benefit from your issue.
          =============== =============== =============== =====

          This posting is provided "AS IS" with no warranties, and confers no rights.

          Comment

          Working...