I've configured a Grid control to use a custom form. Wired up the add/edit/delete on the main Grid just fine. Now I'm interested in inserting a Grid on my custom form.
How do I access the Insert/Update/Delete commands on the 'sub' Grid on my custom form? Also, how do I pass the DataKeyName value to the sub Grid? (this also applies to a ComboBox I'm trying to filter by the datakeyname).
Thanks in advance!
Brandon
How do I access the Insert/Update/Delete commands on the 'sub' Grid on my custom form? Also, how do I pass the DataKeyName value to the sub Grid? (this also applies to a ComboBox I'm trying to filter by the datakeyname).
Thanks in advance!
Brandon
5 Answers, 1 is accepted
0
Brandon
Top achievements
Rank 1
answered on 17 Apr 2008, 11:12 PM
How do I access the Insert/Update/Delete commands on the 'sub' Grid on my custom form
Scratch that, easy enough after the mental block lifted... Still confused on how to get the sub grid to filter on just the DataKeyName of the parent grid...
Thanks again. If I find an answer before someone chimes in I'll post it.
Scratch that, easy enough after the mental block lifted... Still confused on how to get the sub grid to filter on just the DataKeyName of the parent grid...
Thanks again. If I find an answer before someone chimes in I'll post it.
0
Brandon
Top achievements
Rank 1
answered on 18 Apr 2008, 02:39 PM
Ok, so I have another question regarding this nested Grid on the user control I'm working with. How do I obtain the values in the text boxes for the Update and Insert?
So let me summarize and clarify, hopefully.
The big #1:
I have a Rad Grid control listing TableA. Upon Edit, it calls a UserControl. The user control has 4 data sources to bind radComboBoxes to values. 2 of these work great, finding their values like so:
2 of them, however, need to have a WHERE in their SQL statements:
I've tried the session parameters, doesn't seem to work or I'm calling for the wrong key. Any help here would be huge.
#2:
How do I access the values in the subGrid on the UserControl?
Thanks!
Brandon
So let me summarize and clarify, hopefully.
The big #1:
I have a Rad Grid control listing TableA. Upon Edit, it calls a UserControl. The user control has 4 data sources to bind radComboBoxes to values. 2 of these work great, finding their values like so:
CountryValue = Eval("Country") |
Dim index As Integer = CountrySelect.FindItemIndexByValue(CountryValue) |
CountrySelect.SelectedIndex = index |
2 of them, however, need to have a WHERE in their SQL statements:
WHERE PrimaryID = " & DataKeyNameOfTheParentTable |
I've tried the session parameters, doesn't seem to work or I'm calling for the wrong key. Any help here would be huge.
#2:
How do I access the values in the subGrid on the UserControl?
Thanks!
Brandon
0
plamen
Top achievements
Rank 1
answered on 21 Apr 2008, 02:06 PM
Hi Brandon :)
You can use the ItemDataBound event handler. The ItemDataBound event is raised when a data row is bound to data in the RadGrid
Here is an example:
Default.aspx
WebUserControl.ascx
Thanks...
<John:Peel />
You can use the ItemDataBound event handler. The ItemDataBound event is raised when a data row is bound to data in the RadGrid
Here is an example:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title>Untitled Page</title> |
<script runat="server"> |
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditFormItem) && e.Item.IsInEditMode) |
{ |
GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item; |
Session["CustomerID"] = gridEditFormItem.GetDataKeyValue("CustomerID"); |
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
userControl.FindControl("DropDownList1").DataBind(); |
} |
} |
</script> |
</head> |
<body> |
<form id="form1" runat="server"> |
<asp:ScriptManager ID="ScriptManager1" runat="server" /> |
<div> |
<telerik:RadGrid |
DataSourceID="AccessDataSource1" |
ID="RadGrid1" |
runat="server" OnItemDataBound="RadGrid1_ItemDataBound"> |
<MasterTableView DataKeyNames="CustomerID"> |
<Columns> |
<telerik:GridEditCommandColumn> |
</telerik:GridEditCommandColumn> |
</Columns> |
<EditFormSettings |
EditFormType="WebUserControl" |
UserControlName="WebUserControl.ascx"> |
</EditFormSettings> |
</MasterTableView> |
</telerik:RadGrid> |
<asp:AccessDataSource |
ID="AccessDataSource1" |
runat="server" |
DataFile="~/App_Data/Nwind.mdb" |
SelectCommand="SELECT TOP 5 [CustomerID], [CompanyName], [ContactName] FROM [Customers]"> |
</asp:AccessDataSource> |
</div> |
</form> |
</body> |
</html> |
WebUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" %> |
<asp:DropDownList DataTextField="OrderID" DataValueField="OrderID" DataSourceID="AccessDataSource1" ID="DropDownList1" runat="server"> |
</asp:DropDownList> |
<asp:AccessDataSource |
ID="AccessDataSource1" |
runat="server" |
DataFile="~/App_Data/Nwind.mdb" |
SelectCommand="SELECT [OrderID] FROM [Orders] Where CustomerID = ?"> |
<SelectParameters> |
<asp:SessionParameter SessionField="CustomerID" Name="CustomerID" Type="string" /> |
</SelectParameters> |
</asp:AccessDataSource> |
Thanks...
<John:Peel />
0
Brandon
Top achievements
Rank 1
answered on 21 Apr 2008, 05:26 PM
Thank you kindly, John!
I'm using this to populate another RadGrid, not a combobox, so I've removed that code from my vb snippet. However, for some reason my if statement validates TRUE on insert. Everything else seems to work great.
Thanks again,
Brandon
I'm using this to populate another RadGrid, not a combobox, so I've removed that code from my vb snippet. However, for some reason my if statement validates TRUE on insert. Everything else seems to work great.
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then |
Dim FormItem As GridEditFormItem = CType(e.Item, GridEditFormItem) |
Dim MasterID As String = FormItem.GetDataKeyValue("PrimaryID").ToString |
Session.Add("MasterID", MasterID) |
End If |
End Sub |
Thanks again,
Brandon
0
Brandon
Top achievements
Rank 1
answered on 21 Apr 2008, 07:25 PM
Ok, got this fixed. Much appreciated. Working VB code below:
Fixed, working, yay! How does one update the status of a thread? Or do you folks do that?
Brandon
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound |
If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then |
If e.Item.OwnerTableView.IsItemInserted Then |
'adding a record, no DataKeyValue |
Else |
Dim FormItem As GridEditFormItem = CType(e.Item, GridEditFormItem) |
Dim MasterID As String = FormItem.GetDataKeyValue("PrimaryID").ToString |
Session.Add("MasterID", MasterID) |
End If |
End If |
End Sub |
Fixed, working, yay! How does one update the status of a thread? Or do you folks do that?
Brandon