DataGrid Data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Heavey

    #1

    DataGrid Data

    Hello, I am starting to learn how to use the Datagrid and I have a couple of
    questions.

    My datagrid as a checkbox in it. It looks like the following in the
    datagrid...
    <asp:TemplateCo lumn HeaderText="Che ck In">
    <ItemStyle HorizontalAlign ="Center" Width="30px"></ItemStyle>
    <ItemTemplate >
    <asp:CheckBox id="chkReturn" runat="server"
    OnCheckedChange d="CheckItIn" ></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateCol umn>

    I had expected that when I click the checkbox, that the "OnCheckedChang ed"
    event specified would fire. It does not. I added the "AutoPostBack=" True"
    and I can see that it is making a trip back to the server, but the event
    specified is not fired. How do I get the event to fire?

    I wrote a little routine to interogate the values in the datagrid when a
    button is clicked. The problem is that all the values for the checkbox are
    always false. I must be doing something wrong in looking at these values, but
    I am not sure what it is. Here a portion of the routine:

    Dim item As DataGridItem
    Dim itemCnt As Integer = dgCheckIn.Items .Count
    For Each item In dgCheckIn.Items
    Dim cnt3 As Integer = 0
    Dim chkBox As CheckBox
    For cnt3 = 0 To item.Cells(3).C ontrols.Count - 1
    If TypeOf item.Cells(3).C ontrols(cnt3) Is CheckBox Then
    Console.WriteLi ne("Found a Checkbox Control at instance of {0}",
    cnt3)
    chkBox = CType(item.Cell s(3).Controls(c nt3), CheckBox)
    End If
    Next
    Dim bol As Boolean = chkBox.Checked
    Next

    Any Ideas what I am doing wrong?

    Thanks in advance for your assistance!!!!! !!!!


  • Alex Davis

    #2
    Re: DataGrid Data

    Jim,

    Here is what I created and the post back works fine...
    <asp:DataGrid id="dgCheckBoxT est" runat="Server">
    <columns>
    <asp:TemplateCo lumn>
    <ItemTemplate >
    <asp:CheckBox id="chkBox" runat="Server"
    OnCheckedChange d="CheckChanged " AutoPostBack="T rue"/>
    </ItemTemplate>
    </asp:TemplateCol umn>
    </columns>
    </asp:DataGrid>

    Notice the "runat=serv er" in the tags.... here is my code behind the
    scenes...

    public void CheckChanged(ob ject sender, System.EventArg s e)
    {
    Label1.Text = "The dgCheckBox just changed";
    }
    Now granted this is C# vs VB but the concepts are still the same.


    "Jim Heavey" <JimHeavey@hotm ail.com> wrote in message
    news:eCobKMCmDH A.688@TK2MSFTNG P10.phx.gbl...[color=blue]
    > Hello, I am starting to learn how to use the Datagrid and I have a couple[/color]
    of[color=blue]
    > questions.
    >
    > My datagrid as a checkbox in it. It looks like the following in the
    > datagrid...
    > <asp:TemplateCo lumn HeaderText="Che ck In">
    > <ItemStyle HorizontalAlign ="Center" Width="30px"></ItemStyle>
    > <ItemTemplate >
    > <asp:CheckBox id="chkReturn" runat="server"
    > OnCheckedChange d="CheckItIn" ></asp:CheckBox>
    > </ItemTemplate>
    > </asp:TemplateCol umn>
    >
    > I had expected that when I click the checkbox, that the "OnCheckedChang ed"
    > event specified would fire. It does not. I added the[/color]
    "AutoPostBack=" True"[color=blue]
    > and I can see that it is making a trip back to the server, but the event
    > specified is not fired. How do I get the event to fire?
    >
    > I wrote a little routine to interogate the values in the datagrid when a
    > button is clicked. The problem is that all the values for the checkbox[/color]
    are[color=blue]
    > always false. I must be doing something wrong in looking at these values,[/color]
    but[color=blue]
    > I am not sure what it is. Here a portion of the routine:
    >
    > Dim item As DataGridItem
    > Dim itemCnt As Integer = dgCheckIn.Items .Count
    > For Each item In dgCheckIn.Items
    > Dim cnt3 As Integer = 0
    > Dim chkBox As CheckBox
    > For cnt3 = 0 To item.Cells(3).C ontrols.Count - 1
    > If TypeOf item.Cells(3).C ontrols(cnt3) Is CheckBox Then
    > Console.WriteLi ne("Found a Checkbox Control at instance of[/color]
    {0}",[color=blue]
    > cnt3)
    > chkBox = CType(item.Cell s(3).Controls(c nt3), CheckBox)
    > End If
    > Next
    > Dim bol As Boolean = chkBox.Checked
    > Next
    >
    > Any Ideas what I am doing wrong?
    >
    > Thanks in advance for your assistance!!!!! !!!!
    >
    >[/color]


    Comment

    • Alex Davis

      #3
      Re: DataGrid Data

      Jim,

      Here is what I created and the post back works fine...
      <asp:DataGrid id="dgCheckBoxT est" runat="Server">
      <columns>
      <asp:TemplateCo lumn>
      <ItemTemplate >
      <asp:CheckBox id="chkBox" runat="Server"
      OnCheckedChange d="CheckChanged " AutoPostBack="T rue"/>
      </ItemTemplate>
      </asp:TemplateCol umn>
      </columns>
      </asp:DataGrid>

      Notice the "runat=serv er" in the tags.... here is my code behind the
      scenes...

      public void CheckChanged(ob ject sender, System.EventArg s e)
      {
      Label1.Text = "The dgCheckBox just changed";
      }
      Now granted this is C# vs VB but the concepts are still the same.


      "Jim Heavey" <JimHeavey@hotm ail.com> wrote in message
      news:eCobKMCmDH A.688@TK2MSFTNG P10.phx.gbl...[color=blue]
      > Hello, I am starting to learn how to use the Datagrid and I have a couple[/color]
      of[color=blue]
      > questions.
      >
      > My datagrid as a checkbox in it. It looks like the following in the
      > datagrid...
      > <asp:TemplateCo lumn HeaderText="Che ck In">
      > <ItemStyle HorizontalAlign ="Center" Width="30px"></ItemStyle>
      > <ItemTemplate >
      > <asp:CheckBox id="chkReturn" runat="server"
      > OnCheckedChange d="CheckItIn" ></asp:CheckBox>
      > </ItemTemplate>
      > </asp:TemplateCol umn>
      >
      > I had expected that when I click the checkbox, that the "OnCheckedChang ed"
      > event specified would fire. It does not. I added the[/color]
      "AutoPostBack=" True"[color=blue]
      > and I can see that it is making a trip back to the server, but the event
      > specified is not fired. How do I get the event to fire?
      >
      > I wrote a little routine to interogate the values in the datagrid when a
      > button is clicked. The problem is that all the values for the checkbox[/color]
      are[color=blue]
      > always false. I must be doing something wrong in looking at these values,[/color]
      but[color=blue]
      > I am not sure what it is. Here a portion of the routine:
      >
      > Dim item As DataGridItem
      > Dim itemCnt As Integer = dgCheckIn.Items .Count
      > For Each item In dgCheckIn.Items
      > Dim cnt3 As Integer = 0
      > Dim chkBox As CheckBox
      > For cnt3 = 0 To item.Cells(3).C ontrols.Count - 1
      > If TypeOf item.Cells(3).C ontrols(cnt3) Is CheckBox Then
      > Console.WriteLi ne("Found a Checkbox Control at instance of[/color]
      {0}",[color=blue]
      > cnt3)
      > chkBox = CType(item.Cell s(3).Controls(c nt3), CheckBox)
      > End If
      > Next
      > Dim bol As Boolean = chkBox.Checked
      > Next
      >
      > Any Ideas what I am doing wrong?
      >
      > Thanks in advance for your assistance!!!!! !!!!
      >
      >[/color]


      Comment

      • Jim Heavey

        #4
        Re: DataGrid Data

        I determined that my real problem was that in the Page Load event, I was doing
        a databind on the grid the first thing and once this is done, then events
        fire, but since the databind of the datagrid reset all of the chekcbox values,
        this in effect cancelled the events which were associated with checkbox.

        "Alex Davis" <alexdavis@bell south.net> wrote in message
        news:elQmNbEmDH A.1708@TK2MSFTN GP12.phx.gbl...[color=blue]
        > Jim,
        >
        > Here is what I created and the post back works fine...
        > <asp:DataGrid id="dgCheckBoxT est" runat="Server">
        > <columns>
        > <asp:TemplateCo lumn>
        > <ItemTemplate >
        > <asp:CheckBox id="chkBox" runat="Server"
        > OnCheckedChange d="CheckChanged " AutoPostBack="T rue"/>
        > </ItemTemplate>
        > </asp:TemplateCol umn>
        > </columns>
        > </asp:DataGrid>
        >
        > Notice the "runat=serv er" in the tags.... here is my code behind the
        > scenes...
        >
        > public void CheckChanged(ob ject sender, System.EventArg s e)
        > {
        > Label1.Text = "The dgCheckBox just changed";
        > }
        > Now granted this is C# vs VB but the concepts are still the same.
        >
        >
        > "Jim Heavey" <JimHeavey@hotm ail.com> wrote in message
        > news:eCobKMCmDH A.688@TK2MSFTNG P10.phx.gbl...[color=green]
        > > Hello, I am starting to learn how to use the Datagrid and I have a couple[/color]
        > of[color=green]
        > > questions.
        > >
        > > My datagrid as a checkbox in it. It looks like the following in the
        > > datagrid...
        > > <asp:TemplateCo lumn HeaderText="Che ck In">
        > > <ItemStyle HorizontalAlign ="Center" Width="30px"></ItemStyle>
        > > <ItemTemplate >
        > > <asp:CheckBox id="chkReturn" runat="server"
        > > OnCheckedChange d="CheckItIn" ></asp:CheckBox>
        > > </ItemTemplate>
        > > </asp:TemplateCol umn>
        > >
        > > I had expected that when I click the checkbox, that the "OnCheckedChang ed"
        > > event specified would fire. It does not. I added the[/color]
        > "AutoPostBack=" True"[color=green]
        > > and I can see that it is making a trip back to the server, but the event
        > > specified is not fired. How do I get the event to fire?
        > >
        > > I wrote a little routine to interogate the values in the datagrid when a
        > > button is clicked. The problem is that all the values for the checkbox[/color]
        > are[color=green]
        > > always false. I must be doing something wrong in looking at these values,[/color]
        > but[color=green]
        > > I am not sure what it is. Here a portion of the routine:
        > >
        > > Dim item As DataGridItem
        > > Dim itemCnt As Integer = dgCheckIn.Items .Count
        > > For Each item In dgCheckIn.Items
        > > Dim cnt3 As Integer = 0
        > > Dim chkBox As CheckBox
        > > For cnt3 = 0 To item.Cells(3).C ontrols.Count - 1
        > > If TypeOf item.Cells(3).C ontrols(cnt3) Is CheckBox Then
        > > Console.WriteLi ne("Found a Checkbox Control at instance of[/color]
        > {0}",[color=green]
        > > cnt3)
        > > chkBox = CType(item.Cell s(3).Controls(c nt3), CheckBox)
        > > End If
        > > Next
        > > Dim bol As Boolean = chkBox.Checked
        > > Next
        > >
        > > Any Ideas what I am doing wrong?
        > >
        > > Thanks in advance for your assistance!!!!! !!!!
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Jim Heavey

          #5
          Re: DataGrid Data

          I determined that my real problem was that in the Page Load event, I was doing
          a databind on the grid the first thing and once this is done, then events
          fire, but since the databind of the datagrid reset all of the chekcbox values,
          this in effect cancelled the events which were associated with checkbox.

          "Alex Davis" <alexdavis@bell south.net> wrote in message
          news:elQmNbEmDH A.1708@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Jim,
          >
          > Here is what I created and the post back works fine...
          > <asp:DataGrid id="dgCheckBoxT est" runat="Server">
          > <columns>
          > <asp:TemplateCo lumn>
          > <ItemTemplate >
          > <asp:CheckBox id="chkBox" runat="Server"
          > OnCheckedChange d="CheckChanged " AutoPostBack="T rue"/>
          > </ItemTemplate>
          > </asp:TemplateCol umn>
          > </columns>
          > </asp:DataGrid>
          >
          > Notice the "runat=serv er" in the tags.... here is my code behind the
          > scenes...
          >
          > public void CheckChanged(ob ject sender, System.EventArg s e)
          > {
          > Label1.Text = "The dgCheckBox just changed";
          > }
          > Now granted this is C# vs VB but the concepts are still the same.
          >
          >
          > "Jim Heavey" <JimHeavey@hotm ail.com> wrote in message
          > news:eCobKMCmDH A.688@TK2MSFTNG P10.phx.gbl...[color=green]
          > > Hello, I am starting to learn how to use the Datagrid and I have a couple[/color]
          > of[color=green]
          > > questions.
          > >
          > > My datagrid as a checkbox in it. It looks like the following in the
          > > datagrid...
          > > <asp:TemplateCo lumn HeaderText="Che ck In">
          > > <ItemStyle HorizontalAlign ="Center" Width="30px"></ItemStyle>
          > > <ItemTemplate >
          > > <asp:CheckBox id="chkReturn" runat="server"
          > > OnCheckedChange d="CheckItIn" ></asp:CheckBox>
          > > </ItemTemplate>
          > > </asp:TemplateCol umn>
          > >
          > > I had expected that when I click the checkbox, that the "OnCheckedChang ed"
          > > event specified would fire. It does not. I added the[/color]
          > "AutoPostBack=" True"[color=green]
          > > and I can see that it is making a trip back to the server, but the event
          > > specified is not fired. How do I get the event to fire?
          > >
          > > I wrote a little routine to interogate the values in the datagrid when a
          > > button is clicked. The problem is that all the values for the checkbox[/color]
          > are[color=green]
          > > always false. I must be doing something wrong in looking at these values,[/color]
          > but[color=green]
          > > I am not sure what it is. Here a portion of the routine:
          > >
          > > Dim item As DataGridItem
          > > Dim itemCnt As Integer = dgCheckIn.Items .Count
          > > For Each item In dgCheckIn.Items
          > > Dim cnt3 As Integer = 0
          > > Dim chkBox As CheckBox
          > > For cnt3 = 0 To item.Cells(3).C ontrols.Count - 1
          > > If TypeOf item.Cells(3).C ontrols(cnt3) Is CheckBox Then
          > > Console.WriteLi ne("Found a Checkbox Control at instance of[/color]
          > {0}",[color=green]
          > > cnt3)
          > > chkBox = CType(item.Cell s(3).Controls(c nt3), CheckBox)
          > > End If
          > > Next
          > > Dim bol As Boolean = chkBox.Checked
          > > Next
          > >
          > > Any Ideas what I am doing wrong?
          > >
          > > Thanks in advance for your assistance!!!!! !!!!
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...