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

Edit + Update RadGrid

6 Answers 229 Views
Grid
This is a migrated thread and some comments may be shown as answers.
A.mass
Top achievements
Rank 1
A.mass asked on 17 Apr 2009, 02:36 PM


Hello Telerik Team,

I'm using the manual binding way to bind my data [ not using controls, binding @ page-behind code ]

My question is, when the user clicks edit :
1 - How to get the selected row values [ cuz I want to get the text in that row and place it in the controls in the EditItemTemplate ]
2 - @Update click, how to get the values from these textboxes ?!

Please, Note that I read the documentation but its not helping since its using the SqlDataSource control.

Your hints are highly appreciated.
Best Regards,

6 Answers, 1 is accepted

Sort by
0
A.mass
Top achievements
Rank 1
answered on 17 Apr 2009, 07:38 PM
Any code sample or hints ?!
0
prismcarlson
Top achievements
Rank 1
answered on 17 Apr 2009, 09:26 PM
Hello Abdulla,

If I understand correctly you are binding your data to the grid using the NeedDataSource event in the code behind. If this is the case then the code snippet below is how to get the datakey value of the affected row and an example of how to get the text entered into a textbox field of the affected row.

Protected Sub myGrid_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles myGrid.UpdateCommand
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim EDITEDTEXT As String = CType(item("myTextbox").Controls(0), TextBox).Text           
            Dim myUniqueID As Integer = CType(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("uniqueID"), Integer)

           //SQL update statement goes here
        End If
    End Sub
0
A.mass
Top achievements
Rank 1
answered on 18 Apr 2009, 07:47 AM


Hello chabian,

The way to get the Primary Key of the edited row is working fine, the problem that I'm facing that onEdit I want the value to be shown in the textboxes for the edited row.

My RadGrid do the following :
- Its getting the list of links depending on the user logged in.
- I'm using a telerik:GridHyperLinkColumn to display this with DataTextField="linkName" DataNavigateUrlFields="link".
- On Edit link clicked I want to get the text of that hyperlink to a textbox and the navigateUrl to another one.
- On Update, I want to update my DB.

in Visual Studio's gridview that would be really easy to accomplish.

My RadGrid code like the following :
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"
    </telerik:RadScriptManager> 
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"  
        AutoGenerateEditColumn="True" GridLines="None"  
        AutoGenerateDeleteColumn="True"
<MasterTableView DataKeyNames="linkID"
<RowIndicatorColumn Visible="False"
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn Visible="False" Resizable="False"
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
 
    <Columns> 
        <telerik:GridHyperLinkColumn DataTextField="linkName" DataNavigateUrlFields="link" HeaderText="link"  
            SortExpression="link" UniqueName="linkName"
        </telerik:GridHyperLinkColumn> 
    </Columns> 
     
<EditFormSettings> 
<PopUpSettings ScrollBars="None"></PopUpSettings> 
</EditFormSettings> 
</MasterTableView> 
    </telerik:RadGrid> 

And the code-behind like the following :

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data; 
using Telerik.Web.UI; 
using System.Data.SqlClient; 
using System.Configuration; 
 
public partial class Default2 : System.Web.UI.Page 
    private static String connStr = ConfigurationManager.ConnectionStrings["ConnectionString1"].ToString(); 
    private static SqlConnection conn = new SqlConnection(connStr); 
    private static SqlCommand comm = new SqlCommand(); 
    private static DataSet ds; 
    private static SqlDataAdapter adptr = new SqlDataAdapter(); 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
            Session["dtMyLinks"] = getLinks("test""choosen"); 
            RadGrid1.DataSource = (DataTable)Session["dtMyLinks"]; 
            RadGrid1.DataBind(); 
    } 
 
    public static DataTable getLinks(String employeeID, String linkType) 
    { 
        DataTable dt = new DataTable(); 
        comm = new SqlCommand(); 
        comm.Parameters.Clear(); 
        ds = new DataSet(); 
 
        comm.CommandType = CommandType.StoredProcedure; 
        comm.CommandText = "GetLinks"
        comm.Connection = conn; 
        comm.Parameters.AddWithValue("@employeeID", employeeID); 
        comm.Parameters.AddWithValue("@linkType", linkType); 
 
        adptr = new SqlDataAdapter(comm); 
        adptr.Fill(ds); 
 
        dt = ds.Tables[0]; 
 
        return dt; 
    } 
 


The stored procedure runs a script that returns list of links
select linkID, linkName, link, employeeID from links


A hint or sample would be appreciated.
Best Regards,
0
A.mass
Top achievements
Rank 1
answered on 18 Apr 2009, 07:30 PM
I solved this.

Thank you.
0
Michele
Top achievements
Rank 2
answered on 12 Jun 2009, 10:54 AM
Hello A.mass,
can you please tell me how you solved it??
I'm facing the same problem right now...
Thanks

Paolo
0
Monalisa
Top achievements
Rank 1
answered on 22 Jul 2009, 01:37 PM
Hi,

I am also facing same problem. I use item template and in edit command I get the PK value of that rows. But I need that PK value in Page_Load. SO can anybody have any idea how to solve this.

Please reply soon its urgent.

Thanks,
Monalisa
Tags
Grid
Asked by
A.mass
Top achievements
Rank 1
Answers by
A.mass
Top achievements
Rank 1
prismcarlson
Top achievements
Rank 1
Michele
Top achievements
Rank 2
Monalisa
Top achievements
Rank 1
Share this question
or