Results 1 to 3 of 3

Thread: DropDownLIst in Datagrid

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    121

    DropDownLIst in Datagrid

    Hi Friends

    I am trying to populate a DropDownList form database which is inside a datagrid.

    The .ASPX page code is like this

    Code:
    <asp:DataGrid ID="dgMultiplePayment" Runat="server" CssClass="input" AutoGenerateColumns=False  >
    										<Columns>
    											<asp:TemplateColumn>
    												<ItemTemplate>
    													<input type="checkbox" runat="server" id="chkPaymentMethod" NAME="chkPaymentMethod">
    												</ItemTemplate>
    											</asp:TemplateColumn>
    											<asp:TemplateColumn HeaderText="Payment Method">
    												<ItemTemplate>
    													<asp:DropDownList ID=drpPaymentMethods Runat=server CssClass=input></asp:DropDownList>
    												</ItemTemplate>
    											</asp:TemplateColumn>
    										</Columns>
    									</asp:DataGrid>
    But in the code behind page when I try to refrence this DropDownlist to bind it to data source by its ID I am not able to do it.

    Code in my .CS page is like this
    Code:
    DataTable batchDT = new DataTable();
    				batchDT = objList.getBatch();
    
    drpPaymentMethods.DataValueField = "icageId";
    				drpPaymentMethods.DataTextField = "vCageRef";
    				drpPaymentMethods.DataSource = batchDT;
    				drpPaymentMethods.DataBind();
    				drpPaymentMethods.Items.Insert(0,new ListItem("Select Batch","")) ;
    Am I doing something wrong?Is there something else to bind this DDL to datasource.

    Please help

    Thanks in Advance.
    -Sachien

  2. #2
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: DropDownLIst in Datagrid

    If its in a datagrid, you will have to do the DropDownList binding in the OnItemDataBound event, that way it will do it for each DDL. In a datagrid, if you have multiple rows, each DDL in each row is treated separately.

    It will be something like this:

    Dim tempDrp as DropDownList

    tempDrp = CType( e.Item.findControl("drpPaymentMethods"), DropDownList )

    drpPaymentMethods.DataTextField = "..." ...

  3. #3
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: DropDownLIst in Datagrid

    To clarify, That's the DataGrid's OnItemDataBound event...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width