This is a migrated thread and some comments may be shown as answers.

[Solved] Update on Selection

6 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CarlosCisneros
Top achievements
Rank 1
CarlosCisneros asked on 23 Jun 2009, 09:49 PM
Hi, can some ome help me.

I need to make an update once i select a row, i have a GridTemplateColumn as in Telerik Example (http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultvb.aspx) and I need to update a database field (true/false) once is checked or unchecked. is there a way to do this?


<telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn"
                            <HeaderTemplate> 
                             <asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True" runat="server"></asp:CheckBox> 
                            </HeaderTemplate> 
                            <ItemTemplate> 
                                <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
 

here is how i am trying to make the update.

Protected Sub ToggleRowSelection(ByVal sender As ObjectByVal e As EventArgs) 
        CType(CType(sender, CheckBox).Parent.Parent, GridItem).Selected = CType(sender, CheckBox).Checked 
 
        Dim State As String = CType(RadGrid1.MasterTableView.Items(0).FindControl("CheckBox1"), CheckBox).Checked.ToString 
        If State = "True" Then 
            SqlDataSourceArticulos.UpdateParameters(0).DefaultValue = 1 
            SqlDataSourceArticulos.UpdateParameters(1).DefaultValue = RadGrid1.SelectedValues("Solicitud"
            SqlDataSourceArticulos.UpdateParameters(2).DefaultValue = RadGrid1.SelectedValues("NumPartida"
            SqlDataSourceArticulos.Update() 
        Else 
            SqlDataSourceArticulos.UpdateParameters(0).DefaultValue = 0 
            SqlDataSourceArticulos.UpdateParameters(1).DefaultValue = RadGrid1.SelectedValues("Solicitud"
            SqlDataSourceArticulos.UpdateParameters(2).DefaultValue = RadGrid1.SelectedValues("NumPartida"
            SqlDataSourceArticulos.Update() 
        End If 
        RadGrid1.Rebind() 
        CType(RadGrid1.MasterTableView.Items(0).FindControl("CheckBox1"), CheckBox).Checked = State 
    End Sub 

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 24 Jun 2009, 09:23 AM
Hello Carlos,

To achieve the desired functionality, please give a try of the code snippet bellow:
ASPX:
<asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server" Checked='<%# Eval("<your bool field>")%>'></asp:CheckBox> 

Another approach is to find CheckBox on ItemDataBound event based on the data field value and set it as checked or unchecked.

I hope this helps.
 
Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
CarlosCisneros
Top achievements
Rank 1
answered on 24 Jun 2009, 03:26 PM
Thanks it really help me, but now i can't reference row when I uncheck the row. I'm using :

RadGrid1.SelectedValues("Solicitud")
do you know any other way to do it?

0
CarlosCisneros
Top achievements
Rank 1
answered on 24 Jun 2009, 03:52 PM
I forgot to mention, i need to get information from columns once is unchecked select column.
0
Pavlina
Telerik team
answered on 24 Jun 2009, 04:45 PM
Hi Carlos,

For more information about how to access the row when is checked or unchecked, please refer to the following help article:
Accessing cells and rows

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
CarlosCisneros
Top achievements
Rank 1
answered on 25 Jun 2009, 10:57 PM
I migth be missing something, but this is my sub.
Protected Sub ToggleRowSelection(ByVal sender As ObjectByVal e As EventArgs)     
        CType(CType(sender, CheckBox).Parent.Parent, GridItem).Selected = CType(sender, CheckBox).Checked     
        Dim Status As String = CType(RadGrid1.MasterTableView.Items(0).FindControl("CheckBox1"), CheckBox).Checked.ToString     
        Dim cell As TableCell = Nothing    
        Dim dataItem As GridDataItem = CType(e       
        CType(dataItem.FindControl("Solicitud"), TextBox).Text = ""    
        cell = dataItem("Solicitud")     
   
    
        If Status = "True" Then    
            SqlDataSourceArticulos.UpdateParameters(0).DefaultValue = 1     
            SqlDataSourceArticulos.UpdateParameters(1).DefaultValue = RadGrid1.SelectedValues("Solicitud")     
            SqlDataSourceArticulos.UpdateParameters(2).DefaultValue = RadGrid1.SelectedValues("NumPartida")     
            SqlDataSourceArticulos.Update()     
               
        Else    
            SqlDataSourceArticulos.UpdateParameters(0).DefaultValue = 0     
            'Dim ss As String = CType(RadGrid1.MasterTableView.ExtractValuesFromItem("Solicitud", Label).ToString()     
            SqlDataSourceArticulos.UpdateParameters(1).DefaultValue = RadGrid1.SelectedValues("Solicitud")     
            SqlDataSourceArticulos.UpdateParameters(2).DefaultValue = RadGrid1.SelectedValues("NumPartida")     
            SqlDataSourceArticulos.Update()     
                
        End If    
        RadGrid1.Rebind()     
        CType(RadGrid1.MasterTableView.Items(0).FindControl("CheckBox1"), CheckBox).Checked = Status   
    End Sub    
 
 i already checked page you told me to, but in order to use e.item I need to be on a sub with ByVal e As Telerik.Web.UI.GridUpdatedEventArgs not in a sub with ByVal e As EventArgs am i right? if thats so, how can i access value of a cell inside sub posted above.

thanks in advanced.
0
Pavlina
Telerik team
answered on 01 Jul 2009, 09:58 AM
Hi Carlos,

In order to progress in the resolution of this matter I will ask you to open a formal support ticket and send us a simple runnable application demonstrating the issue you are facing. Thus I could do all my best to find a quick solution/fix of this problem.

Looking forward for your reply.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
CarlosCisneros
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
CarlosCisneros
Top achievements
Rank 1
Share this question
or