H
Hongbo
Hi,
I have a GridView like this one:
==
<asp:gridview runat="server" id="gvCategory" allowpaging="true" allowsorting="true"
alternatingrowstyle-backcolor="#B9DFC7" autogeneratecolumns="false"
pagesize="20" width="550px" datasourceid="prodList">
<headerstyle backcolor="#B9DFC7" />
<columns>
<asp:templatefield>
<itemtemplate>
<asp:checkbox runat="server" id="chkAddToCart" />
</itemtemplate>
</asp:templatefield>
<asp:boundfield headertext="productID" datafield="productID" visible="false" />
<asp:templatefield>
<itemtemplate>
<a href='<%# "/product/productDetail.aspx?productID="
+DataBinder.Eval(Container.DataItem, "productId") %>'><img alt="" src='<%# "/images/prod/"
+DataBinder.Eval(Container.DataItem, "thumbImg") %>' style="border:none" /></a>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
==
In .Net 1.x, the DataGrid works with the following code:
==
foreach (DataGridItem dgi in DataGrid1.Items)
{
chb = (CheckBox)dgi.FindControl("chkAddToCart");
if (chb.Checked)
{
string pid=dgi.Cells[1].Text;
}
}
==
So I tried:
==
foreach (GridViewRow gvr in gvCategory.Rows)
{
if(gvr.HasControls()==true)
{
chb = (CheckBox)gvr.FindControl("chkAddToCart");
if (chb.Checked)
{
string pid = gvr.Cells[1].Text;
}
}
}
==
But gvr.Cells[1].Text returns nothing. What's wrong here?
Would you please tell me how to read data from the 2nd field--the Cells[1]
(i.e. <asp:boundfield headertext="productID" datafield="productID" visible="false" />)
in each row of the above GridView?
Thank you
hb
I have a GridView like this one:
==
<asp:gridview runat="server" id="gvCategory" allowpaging="true" allowsorting="true"
alternatingrowstyle-backcolor="#B9DFC7" autogeneratecolumns="false"
pagesize="20" width="550px" datasourceid="prodList">
<headerstyle backcolor="#B9DFC7" />
<columns>
<asp:templatefield>
<itemtemplate>
<asp:checkbox runat="server" id="chkAddToCart" />
</itemtemplate>
</asp:templatefield>
<asp:boundfield headertext="productID" datafield="productID" visible="false" />
<asp:templatefield>
<itemtemplate>
<a href='<%# "/product/productDetail.aspx?productID="
+DataBinder.Eval(Container.DataItem, "productId") %>'><img alt="" src='<%# "/images/prod/"
+DataBinder.Eval(Container.DataItem, "thumbImg") %>' style="border:none" /></a>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
==
In .Net 1.x, the DataGrid works with the following code:
==
foreach (DataGridItem dgi in DataGrid1.Items)
{
chb = (CheckBox)dgi.FindControl("chkAddToCart");
if (chb.Checked)
{
string pid=dgi.Cells[1].Text;
}
}
==
So I tried:
==
foreach (GridViewRow gvr in gvCategory.Rows)
{
if(gvr.HasControls()==true)
{
chb = (CheckBox)gvr.FindControl("chkAddToCart");
if (chb.Checked)
{
string pid = gvr.Cells[1].Text;
}
}
}
==
But gvr.Cells[1].Text returns nothing. What's wrong here?
Would you please tell me how to read data from the 2nd field--the Cells[1]
(i.e. <asp:boundfield headertext="productID" datafield="productID" visible="false" />)
in each row of the above GridView?
Thank you
hb