I'm having a radgrid on a page that contains 6 columns including a dropdownlist. The dropdown list value can be changed by the user at runtime. There is a save button (asp:button) and I'm looking to get all values of the row/columns on a button click on the page. Please help how to extract all the values from the grid. Many thanks.
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 25 Mar 2014, 11:13 AM
Hi Peter,
I guess that you want to access the values of RadGrid in Edit Mode. Please have a look into the sample code snippet which works fine at my end.
ASPX:
C#:
Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
I guess that you want to access the values of RadGrid in Edit Mode. Please have a look into the sample code snippet which works fine at my end.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1"> <MasterTableView> <Columns> <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID"> </telerik:GridBoundColumn> <telerik:GridDropDownColumn DataField="CustomerID" ListTextField="CustomerID" UniqueName="CustomerID" DataSourceID="SqlDataSource1"> </telerik:GridDropDownColumn> <telerik:GridTemplateColumn> <EditItemTemplate> <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" /> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void Button1_Click(object sender, EventArgs e){ Button btn = (Button)sender; GridEditableItem item = (GridEditableItem)btn.NamingContainer; TextBox textboxcol = (TextBox)item["OrderID"].Controls[0]; string columnText=textboxcol.Text; RadComboBox dropdowncol = (RadComboBox)item["CustomerID"].Controls[0]; string selecteditem=dropdowncol.SelectedItem.Text;}Please elaborate your requirement if it doesn't help.
Thanks,
Princy.
0
Peter
Top achievements
Rank 1
answered on 25 Mar 2014, 11:47 AM
Hi Princy,
Many thanks for your reply.
I'm using asp dropdown list in itemtemplate and code is as shown below.
</telerik:GridTemplateColumn>
And the button is not within the grid and its on the page.
On click of the button, I would need to concatenate all the column row values separated by a delimiter and pass on to another interface as a string. the code that I'm using is as follows:
I'm able to loop round the other columns - row in the grid as above, but not the dropdownlist(last column "Weightage") from the grid. Please help me on this.
Many thanks for your reply.
I'm using asp dropdown list in itemtemplate and code is as shown below.
<telerik:GridTemplateColumn HeaderText="Weightage" HeaderStyle-Width="5%" UniqueName="Weightage" DataField="Weightage"><ItemStyle Width="5%" /><ItemTemplate><asp:DropDownList ID="ddlAcuityScore" DataTextField="AcuityScore" runat="server" Width="50px" AutoPostBack="false"></asp:DropDownList> </ItemTemplate></telerik:GridTemplateColumn>
And the button is not within the grid and its on the page.
<asp:Button ID="btnSave" runat="server" Text="Save" />On click of the button, I would need to concatenate all the column row values separated by a delimiter and pass on to another interface as a string. the code that I'm using is as follows:
Dim strbldr As New System.Text.StringBuilderFor Each dataItem As Telerik.Web.UI.GridDataItem In mygrd.Itemssb.Append(dataItem("col1").Text & "|" & dataItem("col2").Text & "|" & dataItem("col3").Text & "|" & dataItem("col4").Text & "|" & dataItem("col5").Text & "~")Next
_strout = strbldr.ToStringI'm able to loop round the other columns - row in the grid as above, but not the dropdownlist(last column "Weightage") from the grid. Please help me on this.
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Mar 2014, 03:15 AM
Hi Peter,
Please try the following code snippet to access the DropDownList on button click.
VB:
Thanks,
Princy
Please try the following code snippet to access the DropDownList on button click.
VB:
Protected Sub btnSave_Click(sender As Object, e As EventArgs) For Each items As GridDataItem In RadGrid1.MasterTableView.Items Dim droplist As DropDownList = DirectCast(items.FindControl("ddlAcuityScore"), DropDownList) ' Gets the selected DataTextField Dim dropdownvalue As String = droplist.SelectedItem.Text NextEnd SubThanks,
Princy