how to bind data to checkbox in datagrid

Discussion in 'ASP .Net Datagrid Control' started by LiFo, Nov 17, 2003.

  1. LiFo

    LiFo Guest

    hi
    i have a datagrid and one colume is a bool
    if i use a normal asp:BoundColumn is shows as true or false
    and i want it to show as a checkbox
    but if i use a asp:TemplateColumn as this
    <asp:TemplateColumn>
    <HeaderTemplate>
    <b>Aktiv</b>
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox Runat="server" ID="checkbox" ></asp:CheckBox>
    </ItemTemplate>
    </asp:TemplateColumn>

    i only get a checkbox how do i bind the data to the checkbox
    and i also want it to only bee able to check the box when it is in edit mode
     
    LiFo, Nov 17, 2003
    #1
    1. Advertising

  2. LiFo

    Jos Guest

    LiFo wrote:
    > hi
    > i have a datagrid and one colume is a bool
    > if i use a normal asp:BoundColumn is shows as true or false
    > and i want it to show as a checkbox
    > but if i use a asp:TemplateColumn as this
    > <asp:TemplateColumn>
    > <HeaderTemplate>
    > <b>Aktiv</b>
    > </HeaderTemplate>
    > <ItemTemplate>
    > <asp:CheckBox Runat="server" ID="checkbox" ></asp:CheckBox>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > i only get a checkbox how do i bind the data to the checkbox
    > and i also want it to only bee able to check the box when it is in
    > edit mode


    For Visual Basic:
    <asp:CheckBox Runat="server" ID="checkbox1"
    Checked='<%# DataBinder.Eval(Container.DataItem, "myField") %>' >
    </asp:CheckBox>

    I suggest using "Checkbox1" and not "Checkbox" for the ID, as Checkbox
    can cause confusion between the type and the instance.

    --

    Jos Branders
     
    Jos, Nov 17, 2003
    #2
    1. Advertising

  3. LiFo

    LiFo Guest

    i am using c# and cant get it to work ???



    "Jos" <> wrote in message
    news:...
    > LiFo wrote:
    > > hi
    > > i have a datagrid and one colume is a bool
    > > if i use a normal asp:BoundColumn is shows as true or false
    > > and i want it to show as a checkbox
    > > but if i use a asp:TemplateColumn as this
    > > <asp:TemplateColumn>
    > > <HeaderTemplate>
    > > <b>Aktiv</b>
    > > </HeaderTemplate>
    > > <ItemTemplate>
    > > <asp:CheckBox Runat="server" ID="checkbox" ></asp:CheckBox>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > >
    > > i only get a checkbox how do i bind the data to the checkbox
    > > and i also want it to only bee able to check the box when it is in
    > > edit mode

    >
    > For Visual Basic:
    > <asp:CheckBox Runat="server" ID="checkbox1"
    > Checked='<%# DataBinder.Eval(Container.DataItem, "myField") %>' >
    > </asp:CheckBox>
    >
    > I suggest using "Checkbox1" and not "Checkbox" for the ID, as Checkbox
    > can cause confusion between the type and the instance.
    >
    > --
    >
    > Jos Branders
    >
    >
     
    LiFo, Nov 17, 2003
    #3
  4. LiFo

    Jos Guest

    LiFo wrote:
    > i am using c# and cant get it to work ???


    I checked and it's exactly the same in c#.
    Did you replace "myField" with the actual name of your field,
    for instance "Activ"?

    What is your error message?

    --

    Jos Branders
     
    Jos, Nov 17, 2003
    #4
  5. LiFo

    LiFo Guest

    thanks i have got it to work now
    it was just a small typho

    "Jos" <> wrote in message
    news:%...
    > LiFo wrote:
    > > i am using c# and cant get it to work ???

    >
    > I checked and it's exactly the same in c#.
    > Did you replace "myField" with the actual name of your field,
    > for instance "Activ"?
    >
    > What is your error message?
    >
    > --
    >
    > Jos Branders
    >
    >
     
    LiFo, Nov 17, 2003
    #5
    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. MS Newsgroups

    Bind checkbox in Datagrid

    MS Newsgroups, Jan 23, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    13,773
    eliza81
    Feb 19, 2010
  2. mr2_93
    Replies:
    1
    Views:
    3,665
    mr2_93
    Oct 2, 2005
  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:
    865
    David Wier
    Oct 6, 2006
  4. asp123 vbnet via .NET 247

    How to bind checkbox to one of the values of a datagrid

    asp123 vbnet via .NET 247, Mar 26, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    275
    asp123 vbnet via .NET 247
    Mar 26, 2005
  5. Joey Pang
    Replies:
    4
    Views:
    563
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page