C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

dropdownlist inside datalist


Posted Date: 10 Jan 2009      Posted By: jayachandran      Member Level: Silver     Points: 1   Responses: 1



i have a dropdownlist inside a datalist..... i have 2 tables one is Products table and another one is unit table.....in that product table fields are (Primary key)product id, productname; unit table fields are ( primary key (unitid),Weight( for ex .. 500gms,250gms) ,intproduct id(foreign key)..... in that datalist i displayed the product names .... plz help how to load the particular product weight in that dropdownlist.........




Responses

Author: Parul Rathore    10 Jan 2009Member Level: SilverRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

Update below code according to ur need, This will solve ur problem definetly--
<asp:DataList ID="dtlResult" Width="905" DataKeyField="resultid" runat="server" RepeatColumns="1"
RepeatDirection="Horizontal" onitemdatabound="dtlResult_ItemDataBound">
<ItemTemplate>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="60%">
<%# Eval("Title") %>
</td>
<td >
<asp:DropDownList ID="cboBoard" Width="99%" runat="server">
</asp:DropDownList>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

protected void dtlResult_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList cboboard = (DropDownList)e.Item.FindControl("cboBoard");
if (cboboard != null)
{

FillCombo(cboboard, "select title,id from tbl_uni_board_master ", "id", "title");// user defined function to fill dropdownlist
Int64 id = Convert.ToInt64(DataBinder.Eval(e.Item.DataItem, "resultid"));
try
{
string strQuery = "select b.id from tbl_results r ,tbl_uni_board_master b where r.boardid=b.id and r.resultid=" + id;
cboboard.SelectedValue = SqlHelper.ExecuteScalar(Connection.ConnectionString, CommandType.Text, strQuery).ToString(); // execute query to get id
cboboard.Items.RemoveAt(0);
}
catch { }
}

}

please mark the response



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : I have prob with change day part of datetime in C#
Previous : Date
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use