hey, I m creating a small project shopping cart....In gridview. I want to add a Hyperlink to each row of GridvIew, & when the user click on Hyperlink(Add to cart),data go to database..
I add a hyperlink code,but the problem is that,it is not firing,To fire the event for hyperlink..I use RowDataBoundEvent..Mine code as below-
<Columns>
<asp:BoundField HeaderText="Product Name" DataField = "productname"/>
<asp:TemplateField HeaderText="images">
<itemtemplate>
<asp:Image ID="Image1" Width="70" Height="70" runat="server" ImageAlign ="Middle" ImageUrl='<%#"GetDBImage.ashx?id=" + Eval("id") %>' />
</itemtemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Price" DataField ="price" />
<asp:TemplateField HeaderText= "Add To cart" >
<ItemTemplate>
<asp:HyperLink ID="AddTocartHyperlink" runat ="server" Text ="Add To Cart" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
public partial class AddProductsToCart : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=SQL_SERVER_NAME;Initial catalog=DBName;Integrated Security=true");
protected void Page_Load(object sender, EventArgs e)
{
GridViewProducts.DataSource = FetchAllImagesInfo();
GridViewProducts.DataBind();
}
public DataTable GetImages()
{
string sql = "Select * from Products";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
protected void GridViewProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row .RowType == DataControlRowType .DataRow )
{
string a = e.Row.Cells[0].Text;
string b= e.Row.Cells[2].Text;
}
}
hey first tell me that the event that i used RowDataBound,is the Correct event so that when the user suppose clicks on Add To cart of first row,only first row data ts retrievd...
On RowDataBound I just want to get the Column data,Mine above code is right or not???