C# and asp.net using gridview? Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnix
    New Member
    • Mar 2007
    • 3

    C# and asp.net using gridview? Help

    i am very newbie of asp.net..

    i dont know how to get the value for my update event or display ii, from the textbox in gridview.

    code in my html

    [HTML] <form id="form1" runat="server">
    <div>
    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"> </asp:SqlDataSour ce>
    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="Blac k" GridLines="Vert ical" OnSelectedIndex Changed="GridVi ew1_SelectedInd exChanged" BackColor="Whit e" BorderColor="#D EDFDE" BorderStyle="No ne" BorderWidth="1p x" OnRowCancelingE dit="GridView1_ RowCancelingEdi t1" OnRowEditing="G ridView1_RowEdi ting1" OnRowUpdating=" GridView1_RowUp dating1">
    <FooterStyle BackColor="#CCC C99" />
    <Columns>
    <asp:CommandFie ld HeaderText="Edi t" ShowEditButton= "True" ShowHeader="Tru e" />
    </Columns>
    <RowStyle BackColor="#F7F 7DE" />
    <SelectedRowSty le BackColor="#CE5 D5A" Font-Bold="True" ForeColor="Whit e" />
    <PagerStyle BackColor="#F7F 7DE" ForeColor="Blac k" HorizontalAlign ="Right" />
    <HeaderStyle BackColor="#6B6 96B" Font-Bold="True" ForeColor="Whit e" />
    <AlternatingRow Style BackColor="Whit e" />
    </asp:GridView>

    </div>

    </form>[/HTML]



    this one is to change make textbox inside the gridview
    Code:
    protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            bindS();
        }
    Code:
      protected void GridView1_RowUpdating1(object sender, GridViewUpdateEventArgs e)
    {
           GridViewRow row = GridView1.Rows[e.RowIndex];
                TextBox t = row.FindControl("txtName") as TextBox;
         Response.Write("You change it to " + t.text);
    }

    but it returns null.

    i also try this one

    TextBox txtName = (TextBox)GridVi ew1.Rows[e.RowIndex].FindControl("t xtName");

    but still returns null

    in my html code i dont make any textbox.

    whats wrong with this code? please help me with this... thanks
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Moved to .NET Forum - ASP Forum for Classic ASP only.

    Dr B

    Comment

    • Syoam4ka
      New Member
      • Oct 2007
      • 30

      #3
      removed quote -- confusing

      And where is you txtName? I can't see it - of course it would return null - it doesn't exist.
      In your GridView you should have a TemplateField column in which you have the txtName - then your code will work.

      Comment

      Working...