|
-
Aug 24th, 2006, 05:18 AM
#1
Thread Starter
Lively Member
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
-
Aug 24th, 2006, 11:16 AM
#2
Fanatic Member
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 = "..." ...
-
Aug 24th, 2006, 11:17 AM
#3
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|