Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Re: OnCheckedChanged in Datagrid Doesn't Work


Message #1 by fwest@s... on Tue, 9 Jul 2002 21:13:40
Hi 

If you want to find out the status of a chekbox in a datagrid, use the 
following code

   myChkAdd as checkbox()

   For i = 0 To dgRateList.Items.Count - 1
              myChkAdd = dgRateList.Items(i).FindControl("CheckboxPAdd1")
   next

"CheckboxPAdd1" is the checkbox name given in the datagrid. 
dgRateList is the datagrid name.

When you refer with that name to find out the status, datagrid will have 
no of checkboxes based on your data, that is the reason you should find 
the control in a loop and assign it to another checkbox.

Hope this helps you.





> Hello Lou,

> I am having the same problem.  Would you please share your solution?

> Thanks.

> 
>>  Nevermind, i found the problem. thanks.
>>  
>>  > I have a datagrid with one of the bound columns being a check box.
>>  > 
>>  > I want the checkbox to autopostback so I can catch the event and 
u> pdate 
>>  > the database.
>>  > 
>>  > <asp:DataGrid id="dg"
>>  > runat="server"
>>  > font-size="8"
>>  > OnEditCommand="dg_Edit"
>>  > OnCancelCommand="dg_Cancel"
>>  > OnUpdateCommand="dg_Update"
>>  > OnItemCreated="dg_ItemCreated"
>>  > AutoGenerateColumns="False"
>>  > OnSortCommand="SortRows"
>>  > AllowSorting="True"    
>>  > ShowHeader = "True"
>>  > EditItemStyle-BackColor="yellow"
>>  > DataKeyField="OID"
>>  > CssClass="TableBody">
>>  > 
>>  > ................
>>  > 
>>  > <ASP:TemplateColumn HeaderText="ON/OFF">
>>  > 		 <ItemTemplate>
>>  > 			<ASP:CheckBox 
>>  > 				id="chkStatusNonEdit"
>>  > 				AutoPostBack=True
>>  > 				OnCheckChanged="UpdateStatus"
>>  > 				Checked='<%# CIntToBool(DataBinder.Eval
>>  > (Container.DataItem,"STATUS").ToString()) %>' runat="server" />
>>  > 		</ItemTemplate>
>>  > 
>>  > ..........................................
>>  > 
>>  > void UpdateStatus(Object sender, EventArgs e) {
>>  > 	Response.Write("This Changed.");
>>  > 
>>  > }
>>  > 
>>  > The page is doing autopostback when the checkbox is changed, but the 
>>  > UpdateStatus function is not being 'activated'. 
>>  > 
>>  > 
>>  > 

  Return to Index