p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   gridview binding (http://p2p.wrox.com/showthread.php?t=75870)

vamshidhar August 25th, 2009 03:23 AM

gridview binding

my gridview is not binding..
I have taken Dropdownlist in rowdatabound event when i click the add button the grid should be added.but my grid is not binding...

    protected void grid1_RowDataBound(object sender, GridViewRowEventArgs e)

        if (e.Row.RowType == DataControlRowType.DataRow)
            string s2 = "select subDivisionName from Tbh_SubDivsionMaster";
            SqlDataAdapter ada = new SqlDataAdapter(s2, con);
            DataSet ds = new DataSet();
            DropDownList ddl1 = (DropDownList)e.Row.FindControl("ddl1");
            ddl1.DataSource = ds;
            ddl1.DataTextField = "subDivisionName";


 protected void btnadd_Click(object sender, EventArgs e)

        if (Request.QueryString["uid"] != "")

            grid1.DataSource = ds;


these is my source code
HTML Code:

<asp:GridView ID="grid1"  runat="server" Width="750px" OnRowDataBound="grid1_RowDataBound"  AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None"    >
                                      <HeaderTemplate >
                                        <asp:Label ID="hd1" runat="server" Text="SubDivisionName"> </asp:Label>
                                            <asp:DropDownList ID="ddl1"  runat="server" DataTextField="subDivisionName" AutoPostBack="true" OnSelectedIndexChanged="ddl1_SelectedIndexChanged1" >

Lee Dumond August 25th, 2009 09:52 AM

This code won't work:

DropDownList ddl1 = (DropDownList)e.Row.FindControl("ddl1");

You won't be able to find the ddl in a row, because it is inside a cell. You need to find the cell first, then find the ddl in the cell.

All times are GMT -4. The time now is 05:53 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.