473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

databinding a checkbox in a gridview

i'm trying to change a checkbox on a databound gridview,

on the aspx page, i can bind


<asp:TextBox ID="TextBox1" runat="server" Text ='<%# Bind("Data") %>'></asp:Textbox>

result showing 1 when the page loads up

but if i want a checkbox instead of a textbox, and if the value "Data" is equal to 1 then the checkbox value is true, what kind of code would i use, purely on the aspx


Any idea how i can get this to work, thanks
Oct 17 '07 #1
1 6648
i'm trying to change a checkbox on a databound gridview,

on the aspx page, i can bind


<asp:TextBox ID="TextBox1" runat="server" Text ='<%# Bind("Data") %>'></asp:Textbox>

result showing 1 when the page loads up

but if i want a checkbox instead of a textbox, and if the value "Data" is equal to 1 then the checkbox value is true, what kind of code would i use, purely on the aspx


Any idea how i can get this to work, thanks
Its much like what you did with the textbox man
try:

ASPX:
Expand|Select|Wrap|Line Numbers
  1. <asp:CheckBox id="CheckBox1" runat="server" Checked='<%# bind(intNumber)%>'></asp:CheckBox>
where intNumber is either 1 or 0

C#:
Expand|Select|Wrap|Line Numbers
  1. public bool bind(int data)
  2. {
  3.        if(data == 1)
  4.     return true;            
  5.         else
  6.     return false;
  7. }
you can see the only difference is your setting the "Checked" attribute.

if what you want is to set the value of the checkbox according to a certain column value you can try:

ASPX:
Expand|Select|Wrap|Line Numbers
  1. <asp:CheckBox id="CheckBox2" runat="server" Checked='<%# bind(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "COLUMNNAME"))) %>'>
  2. </asp:CheckBox>
Oct 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Martin | last post by:
Hi, Please can somebody explain how databinding is done on a checkbox list. I have the follwoing code which I would have thought was enough to databind a checkbox, but apparently not. The...
0
by: Harlan.Vossos | last post by:
I am using the GridView component to display data as an HTML table. I create a dataset and manually bind the dataset to the grid as shown below. One of the columns is displayed as a checkbox. I...
1
by: dieter | last post by:
Two-way databinding (as described in http://dotnetjunkies.com/QuickStartv20/aspnet/doc/data/templates.aspx) works fine for me if I use it within aspx-files. However, I would like to use it my...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
1
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in...
1
by: Sergei Shelukhin | last post by:
I have the following problem with gridview. I use MySQL database that has Russian characters in cp1251 encoding, and I get ????????s instead of Russian characters on all my ASP.NET pages. To fix...
1
by: Mark Olbert | last post by:
Has anyone else noticed that the design-time support for databinding in custom controls in ASPNET2 sucks? At least for GridViews? So far I've spent going on two days trying to get the following...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.