如何在gridview项模板中获取标签的值
问题描述:
嗨
我试图从我的gridview获取标签的值,如下所示,我试图获取lblProdId的值
Hi
I am trying to get the value of a label from my gridview as show below I''m trying to get the value of lblProdId
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td rowspan="6" class="style4">
<asp:Image ID="ProdImage" runat="server" Height="152px"
ImageUrl='<%# String.Format(ResolveUrl("ProductImage.ashx")+"{0}{1}","?id=",Eval("propImageId")) %>'
style="margin-left: 0px" Width="172px" BorderColor="Silver"
BorderStyle="Double" BorderWidth="10pt" />
</td>
</tr>
<tr>
<td class="style5">
<asp:Label ID="Label1" runat="server" Text="Product ID:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblProdid" runat="server" Text='<%# Eval("propProdId") %>'></asp:Label>//This label
</td></tr><tr>
<td class="style5">
<asp:Label ID="Label2" runat="server" Text="Description:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("propProdDesc") %>'></asp:Label>
</td></tr><tr>
<td class="style5">
<asp:Label ID="Label3" runat="server" Text="Quantity:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblQty" runat="server" Text= '<%# Eval("propProdQty") %>'></asp:Label>
</td></tr><tr><td class="style5">
<asp:Label ID="Label4" runat="server" Text="Colour:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblColor" runat="server" Text='<%# Eval("propColour") %>'></asp:Label>
</td></tr><tr>
<td class="style5">
<asp:Label ID="Label5" runat="server" Text="Def Design:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblDefDes" runat="server" Text='<%# Eval("propDeflectionDesign") %>'></asp:Label>
</td></tr></table>
</ItemTemplate>
</asp:TemplateField>
我已经尝试过
I''ve tried
switch (e.Row.RowState)
{
case DataControlRowState.Normal:
case DataControlRowState.Alternate:
case DataControlRowState.Edit:
Label myLabel1 = (Label)e.Row.FindControl("lblProdid");
string idField = myLabel1.Text;
// string q = DDlQno.SelectedItem.Text;
//string idField = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "lblProdid"));
GridView rep = (GridView)e.Row.FindControl("GridView1");
// rep.DataSource = yourdatasource;
rep.DataBind();
break;
}
我已经尝试过
And I''ve tried
f (e.Row.RowType != DataControlRowType.DataRow)
{
SqlDataSource s = (SqlDataSource)e.Row.FindControl("obsMeas");
s.SelectParameters[0].DefaultValue = DDlQno.Text;
s.SelectParameters["id"].DefaultValue = ((Label)e.Row.FindControl("lblProdid")).Text;
}
在此先感谢
关于
Thanks in Advance
Regards
答
您可以使用FindControl
方法.
试试类似的东西:
You can useFindControl
method.
Try something like:
foreach (GridViewRow item in myGrid.Rows)
{
Label myLabel = (Label)item.FindControl("lblProdId");
string text = myLabel.Text;
//use the text now
}
如果您处于gridview事件中,并且已经具有行级访问权限,则:
If you are in a gridview event and already have access at row level then:
Label myLabel = (Label)e.Row.FindControl("lblProdId");
string text = myLabel.Text;
//use the text now
它应该起作用.
It should work.
您能告诉我们何时需要标签值吗?
can u tell when u want label value ?