M
Mortar
i have a datagrid with 2 columns.
the 1st column contains an id which will be used by the database for
the selected checkbox records.
the 2nd column is a template column containing a server checkbox
control.
where i'm at:
i can retrieve a count of the selected checkboxes, but don't know how
to get the related id's (in the 1st column).
what i would like to know:
- obviously, how to retrieve the id's for the checkboxes
- on a postback, why do i have to re-create the datagrid on the server
before i can get the selected checkboxes? in other words, if i have a
server function which loops through the datagrid's selected
checkboxes, it won't work unless i create and populate the datagrid
again 1st. It seems inefficient for the server to :
1) re-create the datagrid,
2) then grab the selected checkboxes,
3) do database stuff,
4) then re-create the datagrid again before sending to the client.
why can't i just do steps 2,3 and 4?
my code follows. If someone could fill in my for loop to grab the id's
from the 1st column in the datagrid, i would be grateful.
-----------
<asp:datagrid id="dgResults" runat="server"AutoGenerateColumns="False"
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID"
Visible="false">
<ItemStyle Width="0px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemStyle Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkCol" Runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
-----------
-----------
private void imgSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
int a = 0;
DataGridItemCollection items=dgResults.Items;
for (int i=0; i<items.Count; i++)
{
CheckBox cb= (CheckBox)items.FindControl("chkCol");
if ((cb != null) && cb.Checked)
{
a += 1;
// need to get ID from 1st datagrid column for this checkbox
}
}
sqlBuild();
}
the 1st column contains an id which will be used by the database for
the selected checkbox records.
the 2nd column is a template column containing a server checkbox
control.
where i'm at:
i can retrieve a count of the selected checkboxes, but don't know how
to get the related id's (in the 1st column).
what i would like to know:
- obviously, how to retrieve the id's for the checkboxes
- on a postback, why do i have to re-create the datagrid on the server
before i can get the selected checkboxes? in other words, if i have a
server function which loops through the datagrid's selected
checkboxes, it won't work unless i create and populate the datagrid
again 1st. It seems inefficient for the server to :
1) re-create the datagrid,
2) then grab the selected checkboxes,
3) do database stuff,
4) then re-create the datagrid again before sending to the client.
why can't i just do steps 2,3 and 4?
my code follows. If someone could fill in my for loop to grab the id's
from the 1st column in the datagrid, i would be grateful.
-----------
<asp:datagrid id="dgResults" runat="server"AutoGenerateColumns="False"
<Columns>
<asp:BoundColumn DataField="ID" HeaderText="ID"
Visible="false">
<ItemStyle Width="0px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemStyle Width="30px"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkCol" Runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
-----------
-----------
private void imgSubmit_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
int a = 0;
DataGridItemCollection items=dgResults.Items;
for (int i=0; i<items.Count; i++)
{
CheckBox cb= (CheckBox)items.FindControl("chkCol");
if ((cb != null) && cb.Checked)
{
a += 1;
// need to get ID from 1st datagrid column for this checkbox
}
}
sqlBuild();
}