Hi,
I have a grid that is bound to a data source:
In the code behind there is the event code:
This works fine.
For the selection of the row I want to use a checkbox:
My Question: How can I get the custom object instance of the current row?
For a hint, I would be grateful
Kind regards.
Christian
I have a grid that is bound to a data source:
<
telerik:RadGrid
ID
=
"gvVerwendungen"
runat
=
"server"
PageSize
=
"15"
AllowPaging
=
"True"
Width
=
"100%"
AutoGenerateColumns
=
"false"
OnNeedDataSource
=
"gvVerwendungen_NeedDataSource"
ShowStatusBar
=
"true"
>
<
MasterTableView
Width
=
"100%"
Summary
=
"RadGrid table"
ShowFooter
=
"true"
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"CheckBoxTemplateColumn"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"Auswahl"
runat
=
"server"
AutoPostBack
=
"True"
OnCheckedChanged
=
"Auswahl_ToggleRowSelection"
/>
</
ItemTemplate
>
<
HeaderTemplate
>
<
asp:CheckBox
ID
=
"headerChkbox"
runat
=
"server"
AutoPostBack
=
"True"
/>
</
HeaderTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
FooterText
=
"Dienststelle"
UniqueName
=
"Dienststelle"
HeaderText
=
"Dienststelle"
DataField
=
"Dienststelle"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FooterText
=
"Beginn"
UniqueName
=
"Beginn"
HeaderText
=
"Beginn"
DataField
=
"Beginn"
DataType
=
"System.DateTime"
DataFormatString
=
"{0:dd/MM/yy}"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FooterText
=
"Sachbezug"
HeaderText
=
"Sachbezug"
DataField
=
"Bezug"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
FooterText
=
"Status"
UniqueName
=
"VerwendungsStatus"
DataField
=
"VerwendungsStatus"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
In the code behind there is the event code:
protected
void
gvVerwendungen_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if
(mitarbeiter !=
null
&& mitarbeiter.VerwendungseintraegeAktuelleUndGeplante !=
null
)
{
this
.gvVerwendungen.DataSource = mitarbeiter.VerwendungseintraegeAktuelleUndGeplante;
}
}
This works fine.
For the selection of the row I want to use a checkbox:
protected
void
Auswahl_ToggleRowSelection(
object
sender, EventArgs e)
{
((sender
as
CheckBox).NamingContainer
as
GridItem).Selected = (sender
as
CheckBox).Checked;
bool
checkHeader =
true
;
foreach
(GridDataItem dataItem
in
gvVerwendungen.MasterTableView.Items)
{
// Auswahl is the name of the ckeckbox-column
if
(!(dataItem.FindControl(
"Auswahl"
)
as
CheckBox).Checked)
{
checkHeader =
false
;
break
;
}
}
GridHeaderItem headerItem = gvVerwendungen.MasterTableView.GetItems(GridItemType.Header)[0]
as
GridHeaderItem;
(headerItem.FindControl(
"headerChkbox"
)
as
CheckBox).Checked = checkHeader;
if
(gvVerwendungen.SelectedItems.Count > 0)
{
// gvVerwendungen is the name of the grid
GridDataItem dataItem = gvVerwendungen.SelectedItems[0]
as
GridDataItem;
// Question: How can I get the bound custom object?
// Problem: The custom object has no ID
}
else
{
tbStellenzeichen.Text =
"Nothing"
;
}
}
My Question: How can I get the custom object instance of the current row?
For a hint, I would be grateful
Kind regards.
Christian