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

Get all rows in radgrid from external button with all rows in edit mode

1 Answer 388 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KV
Top achievements
Rank 1
KV asked on 12 Jun 2012, 05:02 PM
I have a radgrid with all rows in edit mode.
A update button is outside the grid.
<telerik:RadGrid ID="radgridFeeCalc" runat="server" ShowStatusBar="true"
                                    AutoGenerateColumns="False" PageSize="5" AllowPaging="True" AllowSorting="True"
                                    AllowMultiRowSelection="False" AllowAutomaticUpdates="false"
                                    GridLines="None" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"
                                    OnItemDataBound="radgridFeeCalc_ItemDataBound"
                                    >
                                    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
                                    <MasterTableView DataKeyNames="SEQ_NUM, DST_ID"
                                    AllowMultiColumnSorting="True" ShowFooter="True"
                                    CommandItemDisplay="Top" Name="Address" AllowFilteringByColumn="False" TableLayout="Auto" >
                                        <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
                                        <Columns>                                           
                                             
                                            <telerik:GridBoundColumn SortExpression="SEQ_NUM" HeaderText="Sequence" HeaderButtonType="TextButton"
                                                DataField="SEQ_NUM" UniqueName="sEQ_NUM" ReadOnly="true">
                                            </telerik:GridBoundColumn>
                                             
                                            <telerik:GridBoundColumn SortExpression="DESCR" HeaderText="Description" HeaderButtonType="TextButton"
                                                DataField="DESCR" UniqueName="dESCR" ReadOnly="true">
                                            </telerik:GridBoundColumn>
 
                                            <telerik:GridTemplateColumn HeaderText="Calc Amount" DataField="VAL" UniqueName="vAL" >
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="VAL" runat="server" Text='<%# Bind("VAL") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <ItemTemplate >
                                                    <asp:TextBox ID="view_VAL" runat="server" Text='<%# Bind("VAL") %>'></asp:TextBox>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
 
                                            <telerik:GridBoundColumn SortExpression="DST_ID" HeaderText="Distribution Id" HeaderButtonType="TextButton"
                                                DataField="DST_ID" UniqueName="dST_ID" ReadOnly="true">
                                            </telerik:GridBoundColumn>
                                        </Columns>
                                    </MasterTableView>
                                </telerik:RadGrid>
 
                                <telerik:RadButton ID="btnUpdate" runat="server" Text="Update" onclick="btnUpdate_Click"></telerik:RadButton>

How do I get all values from all rows from the grid in an external button "btnUpdate".
I have the following code and can get the datakeyvalues but cannot get the textbox value as the "VAL" textbox is not found.
protected void btnUpdate_Click(object sender, EventArgs e)
        {
            foreach (GridEditFormItem editedItem in radgridFeeCalc.MasterTableView.GetItems(GridItemType.EditFormItem))
            {
                string keyId1 = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["SEQ_NUM"].ToString();
                string keyId2 = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["DST_ID"].ToString();
 
                TextBox combo = ((GridEditFormItem)editedItem).EditFormCell.FindControl("VAL") as TextBox;
                string str1 = combo.Text;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Jun 2012, 06:31 PM
Hello,

get datakey when grid in NORMAL mode.
<telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="true" AutoGenerateColumns="False"
           PageSize="5" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="False"
           AllowAutomaticUpdates="false" GridLines="None" AllowAutomaticDeletes="false"
           AllowAutomaticInserts="false" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowEdit="true">
           <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
           <MasterTableView DataKeyNames="ID" AllowMultiColumnSorting="True" ShowFooter="True"
               CommandItemDisplay="Top" Name="Address" AllowFilteringByColumn="False" TableLayout="Auto">
               <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
               <Columns>
                   <telerik:GridBoundColumn SortExpression="Name" HeaderText="Name" HeaderButtonType="TextButton"
                       DataField="Name" UniqueName="Name" ReadOnly="true">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn HeaderText="Calc Amount"  UniqueName="vAL">
                       <EditItemTemplate>
                           <asp:TextBox ID="VAL" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
                       </EditItemTemplate>
                       <ItemTemplate>
                           <asp:TextBox ID="view_VAL" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
       <telerik:RadButton ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click">
       </telerik:RadButton>
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DateTime dt = DateTime.Today;
 
            dynamic data = new[] {
              new { ID = 1, Name ="name1",CustomDate=dt},
              new { ID = 2, Name = "name2",CustomDate=dt.AddDays(-1)},
              new { ID = 3, Name = "name3",CustomDate=dt.AddDays(-2)},
              new { ID = 4, Name = "Name4",CustomDate=dt.AddDays(-3)},
               new { ID = 5, Name ="name5",CustomDate=dt}
            };
            RadGrid1.DataSource = data;
        }
 
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                string strID = item.GetDataKeyValue("ID").ToString();
                string strview_VAL = (item.FindControl("view_VAL") as TextBox).Text;
                string strName = item["Name"].Text;
            }
        }

get datakey when grid in EDIT mode.
<telerik:RadGrid ID="RadGrid1" runat="server" ShowStatusBar="true" AutoGenerateColumns="False"
           PageSize="5" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="False"
           AllowAutomaticUpdates="false" GridLines="None" AllowAutomaticDeletes="false"
           AllowAutomaticInserts="false" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowEdit="true">
           <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
           <MasterTableView DataKeyNames="ID" AllowMultiColumnSorting="True" ShowFooter="True"
               CommandItemDisplay="Top" Name="Address" AllowFilteringByColumn="False" TableLayout="Auto">
               <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
               <Columns>
                   <telerik:GridBoundColumn SortExpression="Name" HeaderText="Name" HeaderButtonType="TextButton"
                       DataField="Name" UniqueName="Name" ReadOnly="true">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn HeaderText="Calc Amount">
                       <EditItemTemplate>
                           <asp:TextBox ID="VAL" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
                       </EditItemTemplate>
                       <ItemTemplate>
                           <asp:TextBox ID="view_VAL" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
        <telerik:RadButton ID="RadButton1" runat="server" Text="set all row in edit mode" OnClick="RadButton1_Click">
       </telerik:RadButton>
       <telerik:RadButton ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click">
       </telerik:RadButton>
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
      {
          DateTime dt = DateTime.Today;
 
          dynamic data = new[] {
            new { ID = 1, Name ="name1",CustomDate=dt},
            new { ID = 2, Name = "name2",CustomDate=dt.AddDays(-1)},
            new { ID = 3, Name = "name3",CustomDate=dt.AddDays(-2)},
            new { ID = 4, Name = "Name4",CustomDate=dt.AddDays(-3)},
             new { ID = 5, Name ="name5",CustomDate=dt}
          };
          RadGrid1.DataSource = data;
      }
 
      protected void RadButton1_Click(object sender, EventArgs e)
      {
          foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
          {
              item.Edit = true;
          }
          RadGrid1.Rebind();
      }
 
      protected void btnUpdate_Click(object sender, EventArgs e)
      {
          foreach (GridDataItem item in RadGrid1.EditItems)
          {
              GridEditableItem itemToEdit = (item.OwnerTableView.EditMode == GridEditMode.InPlace) ? (GridEditableItem)item : (GridEditableItem)item.EditFormItem;
              string strID = itemToEdit.GetDataKeyValue("ID").ToString();
              string strview_VAL = (itemToEdit.FindControl("VAL") as TextBox).Text;
 
          }
      }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
KV
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or