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

Page with two independant grids

1 Answer 15 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon Channell
Top achievements
Rank 1
Simon Channell asked on 18 Jun 2013, 01:14 PM
I have a asp.net page with two independant grids , both of which can be updated.
When I select edit the grid allows me to edit but clicking Update doesn't work. The form remains in Edit Mode

Definition of grids

<b>SKILLS – MY STRENGTHS </b>
    <br />
    <br />
    <telerik:radajaxloadingpanel id="RadAjaxLoadingPanel1" runat="server" skin="WebBlue">
    </telerik:radajaxloadingpanel>
    <telerik:radgrid id="RadGrid_Strengths" runat="server" autogeneratecolumns="False"
        pagesize="10" allowpaging="True" onneeddatasource="RadGrid_Strengths_NeedDataSource"
        onprerender="RadGrid_Strengths_PreRender" allowautomaticinserts="false" enableajax="true"
        showstatusbar="true" skin="WebBlue" width="600px" onitemdatabound="RadGrid_Strengths_ItemDataBound"
        allowmultirowselection="false" allowautomaticupdates="False" onupdatecommand="RadGrid_Strengths_UpdateCommand">
                            <PagerStyle Mode="NextPrevandNumeric" Position="TopAndBottom" AlwaysVisible="false" />
                            <MasterTableView ShowFooter="true" DataKeyNames="strong_skill_id" CommandItemDisplay="Top" AllowSorting="false" AllowPaging="true" EditMode="InPlace">
                                <CommandItemSettings ShowAddNewRecordButton="false" />
                                <RowIndicatorColumn Visible="true" UniqueName="RowIndicator">
                                    <HeaderStyle Width="20px" BackColor="LightSkyBlue" />
                                </RowIndicatorColumn>
                                <Columns>
                                <telerik:GridBoundColumn UniqueName="Skill_id" HeaderText="No" DataField="strong_skill_id"
                                 SortExpression="strong_skill_id" HeaderStyle-Width="60px" ItemStyle-Width="60px" ItemStyle-Wrap="true" Readonly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="asset_name" HeaderText="Subject" DataField="asset_name"
                                HeaderStyle-Width="100px" ItemStyle-Width="100px" ItemStyle-Wrap="true" Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn DataField="strong_asset_id"
                                    HeaderText="Skill" UniqueName="strong_asset_id" ItemStyle-Width="100px"   HeaderStyle-Width="100px">
                                    <EditItemTemplate>
                                    <asp:DropDownList ID="DDSkills" runat="server"></asp:DropDownList>
                                       </EditItemTemplate>
                           <ItemTemplate>
                     <asp:Label ID="SkillIDLabel" runat="server" Text='<%# Eval("strong_asset_id") %>'></asp:Label>
                 </ItemTemplate>
             </telerik:GridTemplateColumn>
   <telerik:GridEditCommandColumn UniqueName="ColumnEdit" HeaderText="Edit"
   Visible="true" ItemStyle-Width="150px">
    </telerik:GridEditCommandColumn>
   </Columns>
  </MasterTableView>
  </telerik:radgrid>

Second grid

<telerik:radajaxloadingpanel id="RadAjaxLoadingPanel2" runat="server" skin="WebBlue">
    </telerik:radajaxloadingpanel>
    <telerik:radgrid id="RadGrid_Weaknesses" runat="server" autogeneratecolumns="False"
        pagesize="10" allowpaging="True" onneeddatasource="RadGrid_Weaknesses_NeedDataSource"
        onprerender="RadGrid_Weaknesses_PreRender" allowautomaticinserts="false" enableajax="true"
        showstatusbar="true" skin="WebBlue" width="600px" onitemdatabound="RadGrid_Weaknesses_ItemDataBound"
        allowmultirowselection="false" allowautomaticupdates="False" onupdatecommand="RadGrid_Weaknesses_UpdateCommand">
                            <PagerStyle Mode="NextPrevandNumeric" Position="TopAndBottom" AlwaysVisible="false" />
                            <MasterTableView ShowFooter="true" DataKeyNames="weak_skill_id" CommandItemDisplay="Top" AllowSorting="false" AllowPaging="true" EditMode="InPlace">
                                <CommandItemSettings ShowAddNewRecordButton="false" />
                                <RowIndicatorColumn Visible="true" UniqueName="RowIndicator">
                                    <HeaderStyle Width="20px" BackColor="LightSkyBlue" />
                                </RowIndicatorColumn>
                                <Columns>
                                <telerik:GridBoundColumn UniqueName="Skill_id" HeaderText="No" DataField="weak_skill_id"
                                 SortExpression="weak_skill_id" HeaderStyle-Width="60px" ItemStyle-Width="60px" ItemStyle-Wrap="true" Readonly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn UniqueName="asset_name" HeaderText="Subject" DataField="asset_name"
                                HeaderStyle-Width="100px" ItemStyle-Width="100px" ItemStyle-Wrap="true" Visible="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn DataField="weak_asset_id"
                                    HeaderText="Skill" UniqueName="weak_asset_id" ItemStyle-Width="100px"   HeaderStyle-Width="100px">
                                    <EditItemTemplate>
                                    <asp:DropDownList ID="WeakDDSkills" runat="server"></asp:DropDownList>
                                       </EditItemTemplate>
                           <ItemTemplate>
                     <asp:Label ID="WeakSkillIDLabel" runat="server" Text='<%# Eval("weak_asset_id") %>'></asp:Label>
                 </ItemTemplate>
             </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn DataField="weak_skills_text"
                                    HeaderText="DevelopingSkills" UniqueName="weak_skills_text" ItemStyle-Width="100px"   HeaderStyle-Width="100px">
                                    <EditItemTemplate>
                                    <asp:TextBox ID="txtDevelop" runat="server"></asp:TextBox>
                                       </EditItemTemplate>
                           <ItemTemplate>
                     <asp:Label ID="SkillIDLabel" runat="server" Text='<%# Eval("weak_skills_text") %>'></asp:Label>
                 </ItemTemplate>
             </telerik:GridTemplateColumn>
   <telerik:GridEditCommandColumn UniqueName="ColumnEdit" HeaderText="Edit"
   Visible="true" ItemStyle-Width="150px">
    </telerik:GridEditCommandColumn>
   </Columns>
  </MasterTableView>

Update code for one grid

Protected Sub RadGrid_Strengths_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid_Strengths.UpdateCommand
 
 
        Dim success As Integer
 
        Dim skill_idtext As String
        Dim skill_id As Integer
        Dim asset_idtext As String
        Dim asset_id As Integer
 
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
 
        skill_idtext = editedItem.GetDataKeyValue("Skill_id").ToString()
        skill_id = Convert.ToInt32(skill_idtext)
 
        asset_idtext = (TryCast(editedItem.FindControl("DDSkills"), DropDownList)).SelectedValue
        asset_id = Convert.ToInt32(asset_idtext)
 
 
 
        success = careersobj.update_student_strong_skills(studentcode, skill_id, asset_id)
 
 
 
    End Sub

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jun 2013, 11:53 AM
Hi,

I tried to replicate your issue at my side,but couldn't find anything.Please have a look at this example below.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="true"
            OnUpdateCommand="RadGrid1_UpdateCommand">
         <MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID" CommandItemDisplay="Top">
           <CommandItemSettings ShowAddNewRecordButton="false" />
              <Columns>
                    <telerik:GridBoundColumn HeaderText="OrderID" DataField="OrderID" UniqueName="OrderID"  ReadOnly="true"/>
                    <telerik:GridBoundColumn HeaderText="EmployeeID" DataField="EmployeeID" UniqueName="EmployeeID" />
                    <telerik:GridBoundColumn HeaderText="ShipName" DataField="ShipName" UniqueName="ShipName" />
                   <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
             </Columns>
          </MasterTableView>
 </telerik:RadGrid>
 
        <br />
 
<telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource" AllowPaging="true"
            OnUpdateCommand="RadGrid2_UpdateCommand">
       <MasterTableView AutoGenerateColumns="False" DataKeyNames="CustomerID" CommandItemDisplay="Top">
         <CommandItemSettings ShowAddNewRecordButton="false" />
             <Columns>
                    <telerik:GridBoundColumn HeaderText="CustomerID" DataField="CustomerID" UniqueName="CustomerID" />
                    <telerik:GridBoundColumn HeaderText="CompanyName" DataField="CompanyName" UniqueName="CompanyName" />
                    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
            </Columns>
     </MasterTableView>
 </telerik:RadGrid>

VB:
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    Dim selectQuery1 As String = "SELECT * FROM [Orders]"
    Dim adapter1 As New SqlDataAdapter(selectQuery1, conn)
    conn.Open()
    adapter1.Fill(dt1)
    conn.Close()
    RadGrid1.DataSource = dt1
 
End Sub
Protected Sub RadGrid2_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    Dim selectQuery1 As String = "SELECT * FROM [Customers]"
    Dim adapter1 As New SqlDataAdapter(selectQuery1, conn)
    conn.Open()
    adapter1.Fill(dt2)
    conn.Close()
    RadGrid2.DataSource = dt2
 
End Sub
Protected Sub RadGrid1_UpdateCommand(sender As Object, e As GridCommandEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
 
        Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim OrderID As String = edit.GetDataKeyValue("OrderID").ToString()
        Dim txt As TextBox = DirectCast(edit("EmployeeID").Controls(0), TextBox)
        Dim txt2 As TextBox = DirectCast(edit("ShipName").Controls(0), TextBox)
 
        conn.Open()
        Dim query As String = "UPDATE Orders SET EmployeeID ='" + txt.Text + "', ShipName='" + txt2.Text + "' WHERE OrderID = '" + OrderID + "'"
        Dim cmd As New SqlCommand(query, conn)
        cmd.ExecuteNonQuery()
 
        conn.Close()
    End If
End Sub
Protected Sub RadGrid2_UpdateCommand(sender As Object, e As GridCommandEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
 
        Dim edit As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        Dim CustomerID As String = edit.GetDataKeyValue("CustomerID").ToString()
        Dim txt As TextBox = DirectCast(edit("CompanyName").Controls(0), TextBox)
 
        conn.Open()
        Dim query As String = "UPDATE Customers SET CompanyName ='" + txt.Text + "' WHERE CustomerID = '" + CustomerID + "'"
        Dim cmd As New SqlCommand(query, conn)
        cmd.ExecuteNonQuery()
 
        conn.Close()
    End If
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Simon Channell
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or