Hi,
I am having 3 textboxes and 1 gridview.
I want to pass (reflect) the values from textboxes to gridview.
I am not using the database here.
I want to save the data directly from textboxes into the gridview.
The asp code for the gridview goes like this:
<asp:GridView ID="GVWriteDR" runat="server" AllowSorting ="True" CellPadding="4" ForeColor="#333 333" CssClass
="bsgridview "
GridLines="None " AllowPaging="Tr ue" align="center" Width="1%" PageSize ="5"
OnRowDeleting=" GVWriteDR_RowDe leting" OnRowEditing="G VWriteDR_RowEdi ting"
OnSelectedIndex Changed="GVWrit eDR_SelectedInd exChanged" OnRowDataBound= "GVWriteDR_RowD ataBound"
AutoGenerateCol umns="False">
<FooterStyle BackColor="#507 CD1" Font-Bold ="True" ForeColor="Whit e" />
<RowStyle BackColor="#EFF 3FB" />
<EditRowStyle BackColor ="#2461BF" />
<SelectedRowSty le BackColor="#D1D DF1" Font-Bold="True" ForeColor="#333 333" />
<PagerStyle BackColor="#246 1BF" ForeColor="Whit e" HorizontalAlign ="Center" />
<HeaderStyle BackColor="#507 CD1" Font-Bold="True" ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" />
<Columns>
<asp:ButtonFiel d Text="Edit" />
<asp:ButtonFiel d Text="Delete" />
<asp:BoundFie ld DataField="ENam e" HeaderText="ENa me" />
<asp:BoundFie ld DataField ="Dept" HeaderText ="Dept" />
<asp:BoundFie ld DataField =SlNo." Headertext="SlN o." />
</Columns>
</asp:GridView>
The Code behind for this goes like this:
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Ole Db;
using System.Text;
namespace ACMS.aspx_Pages
{
public partial class TestMail : System.Web.UI.P age
{
public string WDRConString = "";
public static DataTable dt;
protected void Page_Load(objec t sender, EventArgs e)
{
WDRConString = ConfigurationMa nager.AppSettin gs["ConnectionStri ng"];
GVWriteDR.Visib le = true;
dt = new DataTable();
}
protected void btnSave_Click(o bject sender, EventArgs e)
{
GVWriteDR.DataS ource = dt;
GVWriteDR.DataB ind();
DataRow dr = dt.NewRow();
dr["EName"] = txtName.Text.To String();
dr["Dept"] = txtDept.Text.To String();
dr["SlNo."] = txtSlNo.Text.To String();
dt.Rows.Add(dr) ;
GVWriteDR.DataS ource = dt;
GVWriteDR.DataB ind();
}
}
}
I am getting the runtime error,
System.Argument Exception: Column 'EName' does not belong to table .
at dr["EName"] = txtName.Text.To String();
Please help me in solving this problem.
Thanks in Advance,
Hiranmaie.
I am having 3 textboxes and 1 gridview.
I want to pass (reflect) the values from textboxes to gridview.
I am not using the database here.
I want to save the data directly from textboxes into the gridview.
The asp code for the gridview goes like this:
<asp:GridView ID="GVWriteDR" runat="server" AllowSorting ="True" CellPadding="4" ForeColor="#333 333" CssClass
="bsgridview "
GridLines="None " AllowPaging="Tr ue" align="center" Width="1%" PageSize ="5"
OnRowDeleting=" GVWriteDR_RowDe leting" OnRowEditing="G VWriteDR_RowEdi ting"
OnSelectedIndex Changed="GVWrit eDR_SelectedInd exChanged" OnRowDataBound= "GVWriteDR_RowD ataBound"
AutoGenerateCol umns="False">
<FooterStyle BackColor="#507 CD1" Font-Bold ="True" ForeColor="Whit e" />
<RowStyle BackColor="#EFF 3FB" />
<EditRowStyle BackColor ="#2461BF" />
<SelectedRowSty le BackColor="#D1D DF1" Font-Bold="True" ForeColor="#333 333" />
<PagerStyle BackColor="#246 1BF" ForeColor="Whit e" HorizontalAlign ="Center" />
<HeaderStyle BackColor="#507 CD1" Font-Bold="True" ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" />
<Columns>
<asp:ButtonFiel d Text="Edit" />
<asp:ButtonFiel d Text="Delete" />
<asp:BoundFie ld DataField="ENam e" HeaderText="ENa me" />
<asp:BoundFie ld DataField ="Dept" HeaderText ="Dept" />
<asp:BoundFie ld DataField =SlNo." Headertext="SlN o." />
</Columns>
</asp:GridView>
The Code behind for this goes like this:
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Data.Ole Db;
using System.Text;
namespace ACMS.aspx_Pages
{
public partial class TestMail : System.Web.UI.P age
{
public string WDRConString = "";
public static DataTable dt;
protected void Page_Load(objec t sender, EventArgs e)
{
WDRConString = ConfigurationMa nager.AppSettin gs["ConnectionStri ng"];
GVWriteDR.Visib le = true;
dt = new DataTable();
}
protected void btnSave_Click(o bject sender, EventArgs e)
{
GVWriteDR.DataS ource = dt;
GVWriteDR.DataB ind();
DataRow dr = dt.NewRow();
dr["EName"] = txtName.Text.To String();
dr["Dept"] = txtDept.Text.To String();
dr["SlNo."] = txtSlNo.Text.To String();
dt.Rows.Add(dr) ;
GVWriteDR.DataS ource = dt;
GVWriteDR.DataB ind();
}
}
}
I am getting the runtime error,
System.Argument Exception: Column 'EName' does not belong to table .
at dr["EName"] = txtName.Text.To String();
Please help me in solving this problem.
Thanks in Advance,
Hiranmaie.
Comment