GridView Setting a checkbox

Discussion in 'ASP .Net' started by tshad, Sep 28, 2009.

  1. tshad

    tshad 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
     
    tshad, Sep 28, 2009
    #1
    1. Advertising

  2. On Sep 28, 5:29 pm, "tshad" <> wrote:
    > 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
     
    Alexey Smirnov, Sep 29, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    0
    Views:
    553
    tshad
    Apr 15, 2005
  2. Vikram

    disable checkbox list checkbox

    Vikram, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,414
    ThunderMusic
    Jan 25, 2006
  3. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    849
    David Wier
    Oct 6, 2006
  4. Jason Huang
    Replies:
    0
    Views:
    569
    Jason Huang
    Jun 29, 2007
  5. Joey Pang
    Replies:
    4
    Views:
    539
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page