Brendan Vogt
Top achievements
Rank 1
Brendan Vogt
asked on 03 Oct 2008, 10:57 AM
Hi,
I have a DetailTables in my grid, and each row in the DetailTables has a checkbox. I am strugging to loop through each row to see if the checkbox is selected or not. I have tried looking for a suitable example but could not find any. Here is my code:
protected void btnClientAccounts_Click(object sender, EventArgs e)
{
foreach (GridDataItem item in rgResults.MasterTableView.DetailTables[0].Items)
{
CheckBox chkSelectAccount = (CheckBox)item.FindControl("chkSelectAccount");
}
}
The item coun stays 0. I'm not sure.
Please can some one help me?
Thanks
Brendan
I have a DetailTables in my grid, and each row in the DetailTables has a checkbox. I am strugging to loop through each row to see if the checkbox is selected or not. I have tried looking for a suitable example but could not find any. Here is my code:
protected void btnClientAccounts_Click(object sender, EventArgs e)
{
foreach (GridDataItem item in rgResults.MasterTableView.DetailTables[0].Items)
{
CheckBox chkSelectAccount = (CheckBox)item.FindControl("chkSelectAccount");
}
}
The item coun stays 0. I'm not sure.
Please can some one help me?
Thanks
Brendan
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 03 Oct 2008, 11:11 AM
Hi Brendan,
Try achieving the desired scenario as shown below.
CS:
Regards
Shinu.
Try achieving the desired scenario as shown below.
CS:
protected void btnClientAccounts_Click(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
if (item.Expanded) |
{ |
GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0]; |
foreach (GridItem childitem in nestedView.Items) |
{ |
CheckBox chkSelectAccount = (CheckBox)childitem.FindControl("chkSelectAccount"); |
} |
} |
} |
} |
Regards
Shinu.
0
Brendan Vogt
Top achievements
Rank 1
answered on 03 Oct 2008, 11:59 AM
Thanks it works just fine. Now the next question that I have is the following. In the DetailTables I have set DataKeyNames="AcctNo". Now how do I get this value back for each row? I thought it would be something in the line of (which I used to get the parent row):
dataItem.GetDataKeyValue("AcctNo");
Please can you advise.
Thanks
Brendan
dataItem.GetDataKeyValue("AcctNo");
Please can you advise.
Thanks
Brendan
0
Princy
Top achievements
Rank 2
answered on 03 Oct 2008, 12:34 PM
Hello Brendan,
You need to set the Name property of the DetailTable and then check for the property to get the DataKeyValues. Check out the code snippet below.
aspx:
cs:
Princy.
You need to set the Name property of the DetailTable and then check for the property to get the DataKeyValues. Check out the code snippet below.
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" > |
<MasterTableView DataSourceID="SqlDataSource1" Name="Master" > |
<DetailTables> |
<telerik:GridTableView DataKeyNames="Age" Name="Detail" DataSourceID="SqlDataSource1" runat="server"> |
</telerik:GridTableView> |
</DetailTables> |
</MasterTableView> |
</telerik:RadGrid> |
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail") |
{ |
string strtxt = (e.Item as GridDataItem).GetDataKeyValue("Age").ToString(); |
} |
} |
Princy.
0
Brendan Vogt
Top achievements
Rank 1
answered on 03 Oct 2008, 12:42 PM
I need to loop through each row in DataTables to get the ID. Here is my code, I need to loop through it when you click on the button:
foreach (GridDataItem item in rgResults.MasterTableView.Items)
{
if (item.Expanded)
{
GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0];
foreach (GridItem childitem in nestedView.Items)
{
CheckBox chkSelectAccount = (CheckBox)childitem.FindControl("chkSelectAccount");
if (chkSelectAccount.Checked)
{
// Get the account number
// Here is where I am trying to get the account number
//object acctInfo = childitem.OwnerTableView.DataKeyValues[0];
Account account = new Account();
//account.AccountNumber =
}
}
}
}
foreach (GridDataItem item in rgResults.MasterTableView.Items)
{
if (item.Expanded)
{
GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0];
foreach (GridItem childitem in nestedView.Items)
{
CheckBox chkSelectAccount = (CheckBox)childitem.FindControl("chkSelectAccount");
if (chkSelectAccount.Checked)
{
// Get the account number
// Here is where I am trying to get the account number
//object acctInfo = childitem.OwnerTableView.DataKeyValues[0];
Account account = new Account();
//account.AccountNumber =
}
}
}
}
0
Shinu
Top achievements
Rank 2
answered on 06 Oct 2008, 10:55 AM
Hi Brendan,
Try the following code snippet to get the DatakeyValue for the checked items in the Detail table on a button click.
CS:
Thanks
Shinu.
Try the following code snippet to get the DatakeyValue for the checked items in the Detail table on a button click.
CS:
protected void Button1_Click(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid2.MasterTableView.Items) |
{ |
if (item.Expanded) |
{ |
GridTableView nestedView = ((GridDataItem)item).ChildItem.NestedTableViews[0]; |
foreach (GridDataItem childitem in nestedView.Items) |
{ |
CheckBox chkSelectAccount = (CheckBox)childitem.FindControl("chkSelectAccount"); |
if (chkSelectAccount.Checked) |
{ |
string StrKey = childitem.GetDataKeyValue("KeyName").ToString(); |
} |
} |
} |
} |
} |
Thanks
Shinu.