Gridview with a checkbox in template field

Posted by Gayathri under ASP.NET on 4/7/2010 | Views : 11631 | Status : [Member] | Replies : 4
Friends,

Sorry for the confusing code posted earlier.

Here is my query --

1) I have a checkbox in the aspx page which is bound to a database field "Intheatres" whose value is either 'Y' or 'N'

2) I am able to display the values from the database in the gridview.

3) but while updating the exisiting datas, i am stuck. how do i update the checkbox value in the table?
I tried using Findcontrol , databinder... but still no result.


Kindly help.




Responses

Posted by: Vuyiswamb on: 4/7/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
am not sure if i understand you correctly. let me ask you some few questions. What is the field that you use to bind the checkbox from the database and what are the possible values of that field?

secondly its easy to find the control. just that am about to sleep now. answer this question i will give you an answer on how to do that tomorrow morning.



Thank you for posting at Dotnetfunda
[Administrator]

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/8/2010 [Member] Bronze

Up
0
Down
Hi, in the gridview databound event you can find the check box , u can acess it by findcontrol and u can work with this..

Thanks
Pavan Kumar
Mark Answer if this fits the need

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gayathri on: 4/8/2010 [Member] Starter

Up
0
Down
Hi,

I am trying to bind a database column "InTheatres" from "Movies" table.

The field can have values as follows "Y" or "N" which means the checkbox will be check when "Y" and "N" when unchecked

datatype of the field is char(1).

so my problem is absolutely stuck on how to update the existing values in the database using this checkbox.

Please help.(if possible with a sample code - tired googling sample codes)



Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/8/2010 [Member] Bronze

Up
0
Down
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CB1" runat="server" Checked='<%# Convert.ToBoolean(Eval("status").ToString().Equals("Y")) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

create table statustable(status char(1))

insert into statustable values('N')
insert into statustable values('Y')
insert into statustable values('N')
insert into statustable values('Y')
insert into statustable values('Y')
insert into statustable values('N')
insert into statustable values('Y')
insert into statustable values('N')

CREATE PROC gET_statustable
AS
BEGIN
SELECT status FROM statustable
END

Dataset ds = new Dataset();
ds = sqlhelper.executedataset("");

GridView1.datasource = ds;
GridView1.databind();


Thanks
Pavan Kumar
Mark Answer if this fits the need

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response