Hi All,
I have a scenario where in i have to use button outside the grid to add,modify,delete and submit the changes in a grid. Im able to trigger the "Add" itemcommand on button click when inserting new row but im not able to capture values which the user has inserted in the row.
e.Item.Cells[2].Text returns " "
Following is the code:
ASPX
Can anyone please tell me how do i capture the values from the newly inserted row?
Thanks,
Vijay
I have a scenario where in i have to use button outside the grid to add,modify,delete and submit the changes in a grid. Im able to trigger the "Add" itemcommand on button click when inserting new row but im not able to capture values which the user has inserted in the row.
e.Item.Cells[2].Text returns " "
Following is the code:
ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ManageSites.aspx.cs" Inherits="ManageSites" %><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><link rel="stylesheet" type="text/css" href="eSOMS.css" /><SCRIPT language="javascript" src="Scripts/ShowError.js"></SCRIPT><script language="javascript" src="Scripts/MiscFunctions.js"></script><head runat="server"> <title>Manage Sites</title> </head><body> <form id="form1" runat="server"> <telerik:RadScriptManager ID="ScriptManager1" runat="server"></telerik:RadScriptManager> <telerik:RadAjaxPanel runat="server"> <table> <tr> <td colspan="4"> <telerik:RadGrid runat="server" ID="rgManageSites" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" EnableAsyncRequests="True" AllowAutomaticInserts="true"> <ClientSettings Selecting-AllowRowSelect="true"></ClientSettings> <MasterTableView AutoGenerateColumns="false" EditMode="InPlace" AllowAutomaticInserts="True" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" CommandItemDisplay="Bottom"> <Columns> <telerik:GridBoundColumn HeaderText="Facility Id" DataField="Site_Code"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="Facility Description" DataField="Site_Description"></telerik:GridBoundColumn> <telerik:GridBoundColumn HeaderText="TimeZone Offset" DataField="Time_Zone_Offset"></telerik:GridBoundColumn> </Columns> </MasterTableView> </telerik:RadGrid> </td> </tr> <tr> <td> <asp:Button ID="btnAdd" runat="server" Text="Add" Width="108px" CausesValidation="false" CssClass="StandardButton" OnClick="btnAdd_Click" CommandName="Add"/> </td> <td> <asp:Button ID="btnDelete" runat="server" Text="Delete" Width="108px" CausesValidation="false" CssClass="StandardButton" OnClick="btnDelete_Click"/> </td> <td> <asp:Button ID="btnModify" runat="server" Text="Modify" Width="108px" CausesValidation="false" CssClass="StandardButton" OnClick="btnModify_Click"/> </td> <td> <asp:Button ID="btnClose" runat="server" Text="Close" Width="108px" CausesValidation="false" CssClass="StandardButton" OnClick="btnClose_Click"/> </td> </tr> </table> </telerik:RadAjaxPanel> </form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using Telerik.Web.UI;using System.Text;using TechAssist.Data;public partial class ManageSites : System.Web.UI.Page{ string userId; DataTable dtSites; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { userId = TechAssist.eSOMS.SharedCommon.CommonUtil.GetUserID(); dtSites = GetMultiSites().Tables[0]; // returns Datatable as source ViewState["dtSites"] = dtSites; // storing it in Viewstate rgManageSites.DataSource = dtSites; } else { //rgManageSites.DataSource = ViewState["dtSites"]; } rgManageSites.ItemCreated += new GridItemEventHandler(rgManageSites_ItemCreated); rgManageSites.ItemCommand += new GridCommandEventHandler(rgManageSites_ItemCommand); } void rgManageSites_ItemCommand(object sender, GridCommandEventArgs e) { switch (e.CommandName) { case "Add": { if ((e.Item is GridDataInsertItem) && e.Item.IsInEditMode) { //e.Item.Cells[2].Text -- returns } rgManageSites.Rebind(); break; } } } void rgManageSites_ItemCreated(object sender, GridItemEventArgs e) { if ((e.Item is GridDataInsertItem) && e.Item.IsInEditMode) { //init insert operation triggered } else if ((e.Item is GridEditableItem) && e.Item.IsInEditMode) { //edit operation triggered } } protected void btnClose_Click(object sender, EventArgs e) { } protected void btnModify_Click(object sender, EventArgs e) { } protected void btnDelete_Click(object sender, EventArgs e) { } protected void btnAdd_Click(object sender, EventArgs e) { rgManageSites.MasterTableView.IsItemInserted = true; if (btnAdd.Text == "Add") { rgManageSites.DataSource = ViewState["dtSites"]; rgManageSites.MasterTableView.InsertItem();// = true; btnAdd.Text = "Apply Add"; } else if (btnAdd.Text == "Apply Add") { btnAdd.Text = "Add"; GridEditableItem insertedItem = rgManageSites.MasterTableView.GetInsertItem(); insertedItem.FireCommandEvent("Add", String.Empty); } } private DataSet GetMultiSites() { StringBuilder sb = new StringBuilder("select US.SITE_CODE,S.SITE_Description,S.Time_Zone_Offset from user_sites US, Sites S "); sb.Append("where US.SITE_CODE = S.SITE_CODE and user_id = '"); sb.Append(userId); sb.Append("'"); TechAssist.Data.Database db = new Database(); TechAssist.Data.DataAdapter da = new TechAssist.Data.DataAdapter(sb.ToString()); DataSet dsSites = new DataSet(); try { da.Fill(dsSites, "Sites"); } catch (System.Exception ex) { TechAssist.eSOMS.SharedCommon.CommonUtil.SetErrorPopup( Page.FindControl("txtErrorMessage"), ex); } return dsSites; }}Can anyone please tell me how do i capture the values from the newly inserted row?
Thanks,
Vijay