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="#333333" CssClass
="bsgridview"
GridLines="None" AllowPaging="True" align="center" Width="1%" PageSize ="5"
OnRowDeleting="GVWriteDR_RowDeleting" OnRowEditing="GVWriteDR_RowEditing"
OnSelectedIndexChanged="GVWriteDR_SelectedIndexCha nged" OnRowDataBound="GVWriteDR_RowDataBound"
AutoGenerateColumns="False">
<FooterStyle BackColor="#507CD1" Font-Bold ="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor ="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:ButtonField Text="Edit" />
<asp:ButtonField Text="Delete" />
<asp:BoundField DataField="EName" HeaderText="EName" />
<asp:BoundField DataField ="Dept" HeaderText ="Dept" />
<asp:BoundField DataField =SlNo." Headertext="SlNo." />
</Columns>
</asp:GridView>
The Code behind for this goes like this:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Text;
namespace ACMS.aspx_Pages
{
public partial class TestMail : System.Web.UI.Page
{
public string WDRConString = "";
public static DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
WDRConString = ConfigurationManager.AppSettings["ConnectionString"];
GVWriteDR.Visible = true;
dt = new DataTable();
}
protected void btnSave_Click(object sender, EventArgs e)
{
GVWriteDR.DataSource = dt;
GVWriteDR.DataBind();
DataRow dr = dt.NewRow();
dr["EName"] = txtName.Text.ToString();
dr["Dept"] = txtDept.Text.ToString();
dr["SlNo."] = txtSlNo.Text.ToString();
dt.Rows.Add(dr);
GVWriteDR.DataSource = dt;
GVWriteDR.DataBind();
}
}
}
I am getting the runtime error,
System.ArgumentException: Column 'EName' does not belong to table .
at dr["EName"] = txtName.Text.ToString();
Please help me in solving this problem.
Thanks in Advance,
Hiranmaie.