GridView Setting a checkbox


T

tshad

I was looking at an example of setting a checkbox in my GridView.It uses the
DataRowView to figure out whether to set it or not.But it uses: dv[6], to
find it.Is there a way to use a column name here? Would the ID
"chkReviewed" be the column name?<asp:TemplateField HeaderText="Reviewed"
ItemStyle-CssClass="alignCenter" SortExpression="Reviewed" Visible="True">
<ItemTemplate > <asp:Label ID="lblReviewed" runat="server" Text='<%#
Eval("Reviewed") %>'></asp:Label> </ItemTemplate> <EditItemTemplate>
<asp:Checkbox ID="chkReviewed" runat="server"></asp:Checkbox>
</EditItemTemplate></asp:TemplateField>protected void
GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList dp= (DropDownList )e.Row .FindControl ("DropDownList1");
DataTable dt = load_department();
for (int i = 0; i < dt.Rows.Count; i++)
{
ListItem lt = new ListItem();
lt.Text = dt.Rows[0].ToString();
dp.Items.Add(lt);
}
dp.SelectedValue = drv[3].ToString();
RadioButtonList rbtnl =
(RadioButtonList)e.Row.FindControl("RadioButtonList1");
rbtnl.SelectedValue = drv[5].ToString();
CheckBoxList chkb = (CheckBoxList)e.Row.FindControl("CheckBoxList2");
chkb.SelectedValue = drv[6].ToString();
}Thanks,Tom
 
Ad

Advertisements

G

Guest

I was looking at an example of setting a checkbox in my GridView.It uses the
DataRowView to figure out whether to set it or not.But it uses: dv[6], to
find it.Is there a way to use a column name here?  Would the ID
"chkReviewed" be the column name?<asp:TemplateField HeaderText="Reviewed"
ItemStyle-CssClass="alignCenter" SortExpression="Reviewed" Visible="True">
<ItemTemplate >       <asp:Label ID="lblReviewed" runat="server"  Text='<%#
Eval("Reviewed") %>'></asp:Label>   </ItemTemplate>    <EditItemTemplate>
<asp:Checkbox ID="chkReviewed" runat="server"></asp:Checkbox>
</EditItemTemplate></asp:TemplateField>protected void
GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
   DataRowView drv = e.Row.DataItem as DataRowView;
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
   if ((e.Row.RowState & DataControlRowState.Edit) > 0)
   {
   DropDownList dp= (DropDownList )e.Row .FindControl ("DropDownList1");
   DataTable dt = load_department();
   for (int i = 0; i < dt.Rows.Count; i++)
   {
   ListItem lt = new ListItem();
   lt.Text = dt.Rows[0].ToString();
   dp.Items.Add(lt);
   }
   dp.SelectedValue = drv[3].ToString();
   RadioButtonList rbtnl =
(RadioButtonList)e.Row.FindControl("RadioButtonList1");
   rbtnl.SelectedValue = drv[5].ToString();
   CheckBoxList chkb = (CheckBoxList)e.Row.FindControl("CheckBoxList2");
   chkb.SelectedValue = drv[6].ToString();



}Thanks,Tom- Hide quoted text -

- Show quoted text -


DataRowView has Item Property of type String to get or set a value in
a specified column.
http://msdn.microsoft.com/en-us/library/0k5w061k.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top