added GridViewRow Dynamically with textbox but missing viewstate

Joined
Jul 25, 2006
Messages
3
Reaction score
0
Hi everyone,

I added a GridViewRow dynamically that has a textbox. I type something into textbox and do a postback, but the textbox is empty. I'm rebinding the gridview on Page_Load everytime, but I can not see where there issue lies. Can someone take a look at my code and see if they can catch it?

aspx file ..................................................

<%@ Page Language="C#" trace ="true" AutoEventWireup="true" CodeFile="Default9.aspx.cs" Inherits="Default9" %>

<!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" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="categoryid" DataSourceID="SqlDataSource1" OnRowDataBound="onGVRowDataBound">

<Columns>
<asp:BoundField DataField="categoryid" HeaderText="categoryid" InsertVisible="False"
ReadOnly="True" SortExpression="categoryid" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JimTestConnectionString %>"
DeleteCommand="DELETE FROM [Category] WHERE [categoryid] = @categoryid" InsertCommand="INSERT INTO [Category] ([description]) VALUES (@description)"
SelectCommand="SELECT top 10 [categoryid], [description] FROM [Category]" UpdateCommand="UPDATE [Category] SET [description] = @description WHERE [categoryid] = @categoryid">

<DeleteParameters>
<asp:parameter Name="categoryid" Type="Int32" />
</DeleteParameters>

<UpdateParameters>
<asp:parameter Name="description" Type="String" />
<asp:parameter Name="categoryid" Type="Int32" />
</UpdateParameters>

<InsertParameters>
<asp:parameter Name="description" Type="String" />
</InsertParameters>

</asp:SqlDataSource>
</div>
</form>
</body>
</html>


cs file..................................

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;

public partial class Default9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}

protected void onGVRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{


Table objParentTable = ((Table)e.Row.Parent);
objParentTable.ID = "Table1";

GridViewRow objTableRow = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
objTableRow.ID = "GVRow2nd";

objParentTable.Controls.Add(objTableRow);


TableCell objTableCell = new TableCell();
objTableCell.ID = "firstCell";
//jTableRow.Cells.Add(objTableCell);
objTableRow.Controls.Add(objTableCell);
TextBox objTB = new TextBox();

PlaceHolder objPH = new PlaceHolder();
objPH.Controls.Add(objTB);
objTableCell.Controls.Add(objPH);
objTableCell.ID = "firstCell2";
objTB.ID = "firsttextbox";
objPH.ID = "firstPlaceHolder";









}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top