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

Access RadGrid columns from a control inside the editforms

2 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sanjay
Top achievements
Rank 1
Sanjay asked on 04 Jan 2011, 07:18 PM
Hello,

I have a ASP repeater control inside the editformsettings and I am using EditMode="EditForms" in the MasterTableView.

I have a 'delete' button inside the Repeater for each row. When I click it I can delete the row and the table data by using the Item command of the repeater with a partialpostback and leaving the Editmode on so that the user can see the item is already removed. But now I also want to update the Grid column which has one of the column as the counts of the files in repeater without closing the Edit form and doing only partial postback to change the value of the column which has the count inside the RadGrid to a value to decrease by one.

1) How do I access the column from the Repeater?

2) Also can I access the Datakeys of the Radgrid from the Reapeter itemcommand. If so how?


Thanks,
Sanjay

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 05 Jan 2011, 09:53 AM
Hello Sanjay,

Check out the following code snippet which shows how to access the column value and DataKeyValue from 'OnItemCommand' event of Repeater.

ASPX:
<EditFormSettings EditFormType="Template" CaptionDataField="EmployeeID">
       <FormTemplate>
          <asp:Repeater ID="rptList" runat="server" DataSourceID="SqlDataSource1"
                 OnItemCommand="rptList_ItemCommand">
               <ItemTemplate>
                   <asp:Button ID="Button1" runat="server" Text="Button" />
               </ItemTemplate>
           </asp:Repeater>
       </FormTemplate>
   </EditFormSettings>

C#:
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
   {
       Repeater reptr = (Repeater)source;
       GridEditFormItem editItem = (GridEditFormItem)reptr.NamingContainer;
       GridDataItem item = (GridDataItem)editItem.ParentItem;//accessing ParentItem
       string colvalue = item["FirstName"].Text; // accessing cell value of ParentItem
       string keyvalue = item.GetDataKeyValue("EmployeeID").ToString();//getting DataKeyValue of ParentItem
   }


Thanks,
Princy.
0
Sanjay
Top achievements
Rank 1
answered on 05 Jan 2011, 05:16 PM
Hi Princy,

Great. Works perfect.
I was using Ctype instead of the Directcast and was getting Nothing/Null as the value

Thanks,
Sanjay
Tags
Grid
Asked by
Sanjay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sanjay
Top achievements
Rank 1
Share this question
or