Professional Web Applications Themes

TemplateColumn with CheckBox DataBind in C# - ASP.NET Data Grid Control

Hi! I'm having problem binding a checkbox to data from a DataSet. I've seen solutions like <%#DataBinder.Eval(Container.DataItem, "ColumnToBind")%> but this code must be added in aspx file and I'm generating the datagrid from code behind. How can i bind data from a dataset to a templatecolumn with ckeckbox in code behind? I'm using C# /thanks...

  1. #1

    Default TemplateColumn with CheckBox DataBind in C#

    Hi!

    I'm having problem binding a checkbox to data from a DataSet.

    I've seen solutions like <%#DataBinder.Eval(Container.DataItem,
    "ColumnToBind")%> but this code must be added in aspx file and I'm
    generating the datagrid from code behind.

    How can i bind data from a dataset to a templatecolumn with ckeckbox
    in code behind? I'm using C#

    /thanks
    Qemajl Guest

  2. #2

    Default TemplateColumn with CheckBox DataBind in C#

    You can make any special data binding in
    datagrid_ItemDataBound event.

    HTH

    Elton WAng
    [email]elton_wanghotmail.com[/email]
    >-----Original Message-----
    >Hi!
    >
    >I'm having problem binding a checkbox to data from a
    DataSet.
    >
    >I've seen solutions like <%#DataBinder.Eval
    (Container.DataItem,
    >"ColumnToBind")%> but this code must be added in aspx
    file and I'm
    >generating the datagrid from code behind.
    >
    >How can i bind data from a dataset to a templatecolumn
    with ckeckbox
    >in code behind? I'm using C#
    >
    >/thanks
    >.
    >
    Elton Wang Guest

  3. #3

    Default Re: TemplateColumn with CheckBox DataBind in C#

    thx... solved the problem with following code in ItemDataBound event.help...

    protected override void OnItemDataBound(DataGridItemEventArgs e)
    {
    try
    {
    string myStr;

    if((e.Item.ItemType != ListItemType.Header) &
    (e.Item.ItemType != ListItemType.Footer))
    {
    myStr = Convert.ToString(DataBinder.Eval(e.Item.DataItem," RegisterVisit"));

    if (myStr == String.Empty)
    ((CheckBox)e.Item.Cells[4].Controls[0]).Visible = false;
    else
    {
    ((CheckBox)e.Item.Cells[4].Controls[0]).Checked = Convert.ToBoolean(myStr);
    }
    }
    }
    catch(Exception E)
    {
    }

    base.OnItemDataBound (e);
    }
    "Elton Wang" <anonymousdiscussions.microsoft.com> wrote in message news:<1e8a01c51cfa$5b413910$a401280aphx.gbl>...
    > You can make any special data binding in
    > datagrid_ItemDataBound event.
    >
    > HTH
    >
    > Elton WAng
    > [email]elton_wanghotmail.com[/email]
    >
    > >-----Original Message-----
    > >Hi!
    > >
    > >I'm having problem binding a checkbox to data from a
    > DataSet.
    > >
    > >I've seen solutions like <%#DataBinder.Eval
    > (Container.DataItem,
    > >"ColumnToBind")%> but this code must be added in aspx
    > file and I'm
    > >generating the datagrid from code behind.
    > >
    > >How can i bind data from a dataset to a templatecolumn
    > with ckeckbox
    > >in code behind? I'm using C#
    > >
    > >/thanks
    > >.
    > >
    Qemajl Guest

Similar Threads

  1. checkbox databind does not work
    By Jim in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: January 5th, 02:08 AM
  2. Help with CheckBox inside a TemplateColumn
    By JasmineC in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: September 2nd, 09:26 AM
  3. TemplateColumn to display Checkbox in DataGrid
    By Paul in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: April 21st, 04:13 AM
  4. Checkbox in TemplateColumn
    By Teemu Keiski in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: August 27th, 08:52 AM
  5. TemplateColumn CheckBox
    By Nus Pieds in forum ASP.NET General
    Replies: 0
    Last Post: July 16th, 02:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139