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

edit a radgrid column

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Satya
Top achievements
Rank 1
Satya asked on 07 Oct 2011, 12:31 PM
hi
 this is satya  the following is my requirement please help me
i  have  radgrid in my page
in that  radgrid one column is editable column for this i use  radgrid item templet
under the radgrid  one  button
 first i edit some rows in the  grid and click the  button 
then the changes  are saved in  database

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Oct 2011, 09:12 AM
Hello Satya,

You can use the following code to achieve the scenario.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" >
            <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                AllowMultiColumnSorting="true" EnableHeaderContextMenu="true">
                <Columns>
                    <telerik:GridBoundColumn DataField="name" HeaderText="name"
                        UniqueName="name">
                    </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn UniqueName="Password1" HeaderText="id">
                     <ItemTemplate>
                      <asp:TextBox ID="txt1" runat="server" Text='<%# Eval("id")%>'>
                     </asp:TextBox>                           
                    </ItemTemplate>
                 </telerik:GridTemplateColumn>
           </Columns>
      </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
  {
      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString());
      foreach (GridDataItem grdItem in RadGrid1.Items) 
     {
         String val=grdItem["name"].Text;
         TextBox txt = (TextBox)grdItem.FindControl("txt1");
      String data = txt.Text;
         con.Open();
         String s = "update test set id='" + data + "' where name='" + val + "'";
         SqlCommand cmd = new SqlCommand(s, con);
         cmd.ExecuteNonQuery();
         con.Close();
     }
  }

Thanks,
Shinu.
Tags
Grid
Asked by
Satya
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or