If you know the list of the students ahead of time (day from your DB) then
you can build a DataSet that has template columns for all of the updatable
fields. You'd then add a button to your form and handle the button's click
event. In the event handler you'd need to iterate over each DataGridRow in
the DataGrid.Rows collection and use FindControl() to access the <asp:TextBox>
or whatever controls you has in the ItemTemplate in your DataGrid. Once you
had those controls, you could then build your update or insert statements
back to the database. Here's a small snippet that might help give you an
idea:
<asp:DataGrid OnItemDataBound="OnItem" CellSpacing="0" CellPadding="2"
DataKeyField="ID" AutoGenerateColumns="False" Runat="server" ID="dg">
<HeaderStyle Wrap="False"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Guest">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "LastName")
%>
,
<%# DataBinder.Eval(Container.DataItem, "FirstName")
%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Choose a Meal">
<ItemTemplate>
<asp:DropDownList SelectedIndex='<%# DataBinder.Eval(Container.DataItem,
"Meal") %>' Runat="server" ID="_meal">
<asp:ListItem Value="0">Beef</asp:ListItem>
<asp:ListItem Value="1">Fish</asp:ListItem>
<asp:ListItem Value="2">Vegetarian</asp:ListItem>
<asp:ListItem Value="3">Child Menu</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Any Food Allergies?">
<ItemTemplate>
<asp:CheckBox Checked='<%# DataBinder.Eval(Container.DataItem,
"Special") %>' Runat="server" ID="_special" Text="Check if Yes">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comments or Details about
Food Allergies">
<ItemTemplate>
<asp:TextBox TextMode="MultiLine" MaxLength="1000"
Width="100%" Runat="server" ID="_comment" Text='<%# DataBinder.Eval(Container.DataItem,
"Comment") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
protected void _button_Click(object sender, System.EventArgs e)
{
foreach (DataGridItem r in dg.Items)
{
DropDownList list = r.Cells[1].FindControl("_meal") as DropDownList;
if (list == null) continue;
CheckBox check = r.Cells[2].FindControl("_special") as CheckBox;
if (check == null) continue;
TextBox text = r.Cells[3].FindControl("_comment") as TextBox;
if (text == null) continue;
// build SQL to go update the database from the control's
values
}
}
-Brock
DevelopMentor
http://staff.develop.com/ballen I want to create a input form to Input the scores of a subject in a
class.
There are about 30 students in a class.
I want to desplay 30 textboxes in a form at a time.
The user can intput the score of all student at a time and press a
summit
button to update to database.
How can I do that?