added GridViewRow Dynamically with textbox but missing viewstate

Discussion in '.NET' started by silverfox_1188, Jul 25, 2006.

  1. silverfox_1188

    silverfox_1188

    Joined:
    Jul 25, 2006
    Messages:
    3
    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";









    }
    }
    }
     
    silverfox_1188, Jul 25, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walterb
    Replies:
    0
    Views:
    1,458
    walterb
    Sep 13, 2007
  2. Jeremy
    Replies:
    1
    Views:
    550
    bruce barker
    Jan 10, 2008
  3. agora1983
    Replies:
    0
    Views:
    658
    agora1983
    Feb 11, 2008
  4. Andy B.
    Replies:
    5
    Views:
    10,214
    Mark Stevens
    Jul 4, 2009
  5. Jeff

    GridviewRow cell reference

    Jeff, May 4, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    821
    Mark Rae [MVP]
    May 4, 2010
Loading...

Share This Page