4 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 20 Dec 2010, 05:35 AM
Hello Alan,
The following code snippet shows how to achieve this. In SelectedIndexChanged event of DropDownList access GridDateItem using NamingContainer property of DropDownList. And then using 'GetDataKeyValue()' method, access its keyvalue.
ASPX:
C#:
Thanks,
Princy.
The following code snippet shows how to achieve this. In SelectedIndexChanged event of DropDownList access GridDateItem using NamingContainer property of DropDownList. And then using 'GetDataKeyValue()' method, access its keyvalue.
ASPX:
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"TerritoryID"
>
<
Columns
>
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:DropDownList
ID
=
"DropDownList1"
runat
=
"server"
DataSourceID
=
"SqlDataSource2"
DataTextField
=
"FirstName"
DataValueField
=
"FirstName"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"DropDownList1_SelectedIndexChanged"
>
</
asp:DropDownList
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
. . . . . . . . . . .
</
DetailTables
>
C#:
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, EventArgs e)
{
DropDownList drplist = (DropDownList)sender;
GridDataItem item = (GridDataItem)drplist.NamingContainer;
string
keyvalue = item.GetDataKeyValue(
"TerritoryID"
).ToString();
}
Thanks,
Princy.
0

Alan Wang
Top achievements
Rank 1
answered on 20 Dec 2010, 04:36 PM
Princy,
It works, thanks a lot.
I do have another question related to detailtables in RadGrid. I know how to double click the Mastertableview to get datakeyvalue using following code:
Question is how I can do the same thing (double click) for the Detailtables in the RadGrid to get the datakeyvalue.
Again thanks a lot for your help
Alan
It works, thanks a lot.
I do have another question related to detailtables in RadGrid. I know how to double click the Mastertableview to get datakeyvalue using following code:
base
.RaisePostBackEvent(source, eventArgument);
if
(source ==
this
.radGridCases && eventArgument.IndexOf(
"RowClicked"
) != -1) {
GridDataItem item = radGridCases.MasterTableView.Items[
int
.Parse(eventArgument.Split(
':'
)[1])];
item.Selected =
true
;
EditCase(item.GetDataKeyValue(
"Id"
).ToString());
}
Question is how I can do the same thing (double click) for the Detailtables in the RadGrid to get the datakeyvalue.
Again thanks a lot for your help
Alan
0

Princy
Top achievements
Rank 2
answered on 21 Dec 2010, 07:12 AM
Hello Alan,
Please take a look at the following sample code snippet which shows how to achieve this.
ASPX:
Java Script:
C#:
Thanks,
Princy.
Please take a look at the following sample code snippet which shows how to achieve this.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid2"
>
<
MasterTableView
Name
=
"Master"
DataKeyNames
=
"EmployeeID"
ClientDataKeyNames
=
"EmployeeID"
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"DetailTable"
DataKeyNames
=
"TerritoryID"
ClientDataKeyNames
=
"TerritoryID"
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
Java Script:
<script type=
"text/javascript"
>
function
RowDblClick(sender, eventArgs) {
if
(eventArgs._tableView.get_name() ==
"Master"
) {
var
dataKeyValue = eventArgs.getDataKeyValue(
"EmployeeID"
);
}
if
(eventArgs._tableView.get_name() ==
"DetailTable"
) {
var
dataKeyValue = eventArgs.getDataKeyValue(
"TerritoryID"
);
}
__doPostBack(
"<%= RadGrid1.ClientID %>"
,
"RowDblClicked:"
+ dataKeyValue);
}
</script>
C#:
protected
override
void
RaisePostBackEvent(IPostBackEventHandler source,
string
eventArgument)
{
base
.RaisePostBackEvent(source, eventArgument);
if
(source ==
this
.RadGrid1 && eventArgument.IndexOf(
"RowDblClicked"
) != -1)
{
string
keyValue = eventArgument.Split(
':'
)[1];
}
}
Thanks,
Princy.
0

Alan Wang
Top achievements
Rank 1
answered on 21 Dec 2010, 03:08 PM
Princy,
It works. Thanks!
Alan
It works. Thanks!
Alan