Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help this?



how to bind the selected product details in datalist when we click one button(details)?
Posted
Comments
Pandya Anil 23-Nov-11 3:36am    
what do you mean by "selected product list" ? the products are bound to any control ? what data you want to bind to datalist, you want to fetch them from db based on your selected item in any other control (i.e. dropdown) ?

to do this first take a datalist in front end write the following source code

<asp:DataList ID="dlGtInfo" runat="server" CaptionAlign="Top" CellPadding="4" RepeatColumns="1" Width="80%" Visible="False">
<AlternatingItemStyle Wrap="False" />

<ItemStyle HorizontalAlign="Left" Wrap="True" />


<ItemTemplate>

//take the itemtamplate you wish to select the product from database


<asp:Label ID="lblemp" runat="server" Text='<%# Eval("empname") %>'></asp:Label></td>

<asp:Label ID="lbldesig" runat="server" Text='<%# Eval("desig") %>'></asp:Label></td>

<asp:Label ID="lblsal" runat="server" Text='<%# Eval("salary") %>'></asp:Label></td>
</ItemTemplate>
</asp:DataList>


and write the server side code
// take a fill method for binding the data to the data list

//fill method for

SqlDataAdapter da=new SqlDataAdapter("select * from tblEmp",con);
DataTable dt = new DataTable();
da.fill(dt);
datalist1.data source=dt;
datalist1.databind();


hope it is working for you.
if not send me reply i will send you my sapmle project.
 
Share this answer
 
Comments
sathiyak 23-Nov-11 3:59am    
again it shows error only...dont know can u help?
add following code to your application.

Markup Code
ASP.NET
<asp:dropdownlist id="ddlProducts" runat="server" xmlns:asp="#unknown" />
<asp:button id="btnBindValue" onclick="btnBindValue_Click" runat="server" xmlns:asp="#unknown" />


Code behind (c#)
C#
void btnBindValue_Click(Object sender,EventArgs e)
{
   //Finding selected value in Button Click event
   string strSelectedValue = ddlProducts.SelectedItem.toStrng();
   //Fill Dataset value from database based on selected value of dropdown
   DataSet ds = GetCalueFromDB(strSelectedValue);
   //Binding dataset to gridview
   gridview1.dataSource = ds;
   gridview1.databind();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900