Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 25th, 2009, 03:23 AM
Authorized User
Points: 91, Level: 1
Points: 91, Level: 1 Points: 91, Level: 1 Points: 91, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Post gridview binding

hi,

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...
Code:
    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();
            ada.Fill(ds);
            DropDownList ddl1 = (DropDownList)e.Row.FindControl("ddl1");
            ddl1.DataSource = ds;
            ddl1.DataTextField = "subDivisionName";
            ddl1.DataBind();
        }


    }


 protected void btnadd_Click(object sender, EventArgs e)
    {

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

            grid1.DataSource = ds;
            grid1.DataBind();

         }
     }
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"     >
                               <Columns>
                                 <asp:TemplateField>
                                      <HeaderTemplate >
                                        <asp:Label ID="hd1" runat="server" Text="SubDivisionName"> </asp:Label>
                                      </HeaderTemplate>
                                      <ItemTemplate>
                                            <asp:DropDownList ID="ddl1"   runat="server" DataTextField="subDivisionName" AutoPostBack="true" OnSelectedIndexChanged="ddl1_SelectedIndexChanged1" >
                                            
                                            </asp:DropDownList>
                                        </ItemTemplate>
                                 </asp:TemplateField>
</asp:GridView>
  #2 (permalink)  
Old August 25th, 2009, 09:52 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

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.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding with Arraylist myself.panku .NET Framework 2.0 2 November 5th, 2008 05:52 AM
binding GridView at runtime! veda Visual Studio 2005 3 August 4th, 2008 06:44 AM
Gridview problem in Binding ndramkumar ASP.NET 2.0 Professional 1 September 2nd, 2007 11:45 PM
Binding dropdownlist to gridView mcgarry101 ASP.NET 2.0 Basics 0 February 13th, 2007 07:12 AM
Binding fields on a gridview aldwinenriquez ASP.NET 2.0 Professional 0 June 1st, 2006 07:50 PM





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