Fetching Telerik RadGrid column and control value on Button Click
Fetching Telerik RadGrid column and control value on Button Click
Step 1: Design web from .aspx page
<div>
<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" AllowPaging="true" PageSize="8" Width="50%" PagerStyle-AlwaysVisible="true"
GridLines="None" AutoGenerateColumns="false"
OnNeedDataSource="RadGrid1_NeedDataSource">
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<HeaderStyle HorizontalAlign="Left" />
<MasterTableView DataKeyNames="name" AutoGenerateColumns="false">
<NoRecordsTemplate>No records found.</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn HeaderText="Name" DataField="Name" />
<telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" />
<telerik:GridBoundColumn HeaderText="Phone" DataField="Phone" />
<telerik:GridTemplateColumn HeaderText="TexValue">
<ItemTemplate>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
<asp:Button ID="btn_get" runat="server" Text="Submit" OnClick="btn_get_Click" />
Step 2: Logic on .Cs page
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Amount");
dt.Columns.Add("Phone");
dt.Rows.Add("Kandy", "12", "8802***2564");
dt.Rows.Add("Sam", "25", "545502*2544");
dt.Rows.Add("Izhar", "32", "95802*2452");
dt.Rows.Add("Vineet", "10.2", "88022564***");
RadGrid1.DataSource = dt;
}
protected void btn_get_Click(object sender, EventArgs e)
{
string strtxt=string.Empty ;
string txt = string.Empty;
foreach(GridDataItem di in RadGrid1.Items)
{
strtxt += di["Name"].Text.ToString()+",";
TextBox textBox1 = (TextBox)(di.FindControl("txt"));
txt += textBox1.Text+",";
}
Response.Write("Column Value : "+strtxt);
Response.Write("<br/>");
Response.Write("Control Value : "+txt);
}
Comments
Post a Comment