By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,361 Members | 1,824 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,361 IT Pros & Developers. It's quick & easy.

DataGrid Data

P: n/a
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:TemplateColumn HeaderText="Check In">
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkReturn" runat="server"
OnCheckedChanged="CheckItIn"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

I had expected that when I click the checkbox, that the "OnCheckedChanged"
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).Controls.Count - 1
If TypeOf item.Cells(3).Controls(cnt3) Is CheckBox Then
Console.WriteLine("Found a Checkbox Control at instance of {0}",
cnt3)
chkBox = CType(item.Cells(3).Controls(cnt3), CheckBox)
End If
Next
Dim bol As Boolean = chkBox.Checked
Next

Any Ideas what I am doing wrong?

Thanks in advance for your assistance!!!!!!!!!
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jim,

Here is what I created and the post back works fine...
<asp:DataGrid id="dgCheckBoxTest" runat="Server">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkBox" runat="Server"
OnCheckedChanged="CheckChanged" AutoPostBack="True"/>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>

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

public void CheckChanged(object sender, System.EventArgs e)
{
Label1.Text = "The dgCheckBox just changed";
}
Now granted this is C# vs VB but the concepts are still the same.
"Jim Heavey" <Ji*******@hotmail.com> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl...
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:TemplateColumn HeaderText="Check In">
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkReturn" runat="server"
OnCheckedChanged="CheckItIn"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

I had expected that when I click the checkbox, that the "OnCheckedChanged"
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).Controls.Count - 1
If TypeOf item.Cells(3).Controls(cnt3) Is CheckBox Then
Console.WriteLine("Found a Checkbox Control at instance of {0}", cnt3)
chkBox = CType(item.Cells(3).Controls(cnt3), CheckBox)
End If
Next
Dim bol As Boolean = chkBox.Checked
Next

Any Ideas what I am doing wrong?

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

Nov 17 '05 #2

P: n/a
Jim,

Here is what I created and the post back works fine...
<asp:DataGrid id="dgCheckBoxTest" runat="Server">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkBox" runat="Server"
OnCheckedChanged="CheckChanged" AutoPostBack="True"/>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>

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

public void CheckChanged(object sender, System.EventArgs e)
{
Label1.Text = "The dgCheckBox just changed";
}
Now granted this is C# vs VB but the concepts are still the same.
"Jim Heavey" <Ji*******@hotmail.com> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl...
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:TemplateColumn HeaderText="Check In">
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkReturn" runat="server"
OnCheckedChanged="CheckItIn"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

I had expected that when I click the checkbox, that the "OnCheckedChanged"
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).Controls.Count - 1
If TypeOf item.Cells(3).Controls(cnt3) Is CheckBox Then
Console.WriteLine("Found a Checkbox Control at instance of {0}", cnt3)
chkBox = CType(item.Cells(3).Controls(cnt3), CheckBox)
End If
Next
Dim bol As Boolean = chkBox.Checked
Next

Any Ideas what I am doing wrong?

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

Nov 17 '05 #3

P: n/a
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" <al*******@bellsouth.net> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
Jim,

Here is what I created and the post back works fine...
<asp:DataGrid id="dgCheckBoxTest" runat="Server">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkBox" runat="Server"
OnCheckedChanged="CheckChanged" AutoPostBack="True"/>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>

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

public void CheckChanged(object sender, System.EventArgs e)
{
Label1.Text = "The dgCheckBox just changed";
}
Now granted this is C# vs VB but the concepts are still the same.
"Jim Heavey" <Ji*******@hotmail.com> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl...
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:TemplateColumn HeaderText="Check In">
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkReturn" runat="server"
OnCheckedChanged="CheckItIn"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

I had expected that when I click the checkbox, that the "OnCheckedChanged"
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).Controls.Count - 1
If TypeOf item.Cells(3).Controls(cnt3) Is CheckBox Then
Console.WriteLine("Found a Checkbox Control at instance of

{0}",
cnt3)
chkBox = CType(item.Cells(3).Controls(cnt3), CheckBox)
End If
Next
Dim bol As Boolean = chkBox.Checked
Next

Any Ideas what I am doing wrong?

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


Nov 17 '05 #4

P: n/a
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" <al*******@bellsouth.net> wrote in message
news:el**************@TK2MSFTNGP12.phx.gbl...
Jim,

Here is what I created and the post back works fine...
<asp:DataGrid id="dgCheckBoxTest" runat="Server">
<columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkBox" runat="Server"
OnCheckedChanged="CheckChanged" AutoPostBack="True"/>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>

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

public void CheckChanged(object sender, System.EventArgs e)
{
Label1.Text = "The dgCheckBox just changed";
}
Now granted this is C# vs VB but the concepts are still the same.
"Jim Heavey" <Ji*******@hotmail.com> wrote in message
news:eC*************@TK2MSFTNGP10.phx.gbl...
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:TemplateColumn HeaderText="Check In">
<ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkReturn" runat="server"
OnCheckedChanged="CheckItIn"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

I had expected that when I click the checkbox, that the "OnCheckedChanged"
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).Controls.Count - 1
If TypeOf item.Cells(3).Controls(cnt3) Is CheckBox Then
Console.WriteLine("Found a Checkbox Control at instance of

{0}",
cnt3)
chkBox = CType(item.Cells(3).Controls(cnt3), CheckBox)
End If
Next
Dim bol As Boolean = chkBox.Checked
Next

Any Ideas what I am doing wrong?

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


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.