如何在后台给GridView内的TemplateField的控件赋值? 10
在唯一一个TemplateField里,有个Label控件,我采用的是C#,想在后台给它赋值,没成功。例如:LabelLabx=gridview1.Rows[0].Cel...
在唯一一个TemplateField里,有个Label控件,我采用的是C#,想在后台给它赋值,没成功。例如:Label Labx=gridview1.Rows[0].Cells[0].FindControl("Labxq") as Label;
Labx.Text="后台";这样不行,出错。谁知道的能告诉我吗? 展开
Labx.Text="后台";这样不行,出错。谁知道的能告诉我吗? 展开
1个回答
展开全部
<asp:GridView ID="GridViewProduct" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" Font-Size="9pt" ForeColor="#333333"
GridLines="None" onpageindexchanging="GridViewProduct_PageIndexChanging">
<Columns>
<asp:TemplateField HeaderText="全选">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chbSelect" />
</ItemTemplate>
<HeaderTemplate>
<input type="checkbox" onclick="GetAllCheckBox(this)" />全选<asp:Button ID="btnalldel"
runat="server" Text="全部删除" Font-Size="8pt" Width="60px"
BackColor="AntiqueWhite" onclick="btnalldel_Click" OnClientClick="return confirm('确定全部删除吗?')" />
</HeaderTemplate>
<ControlStyle Width="50px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblId" runat="server"
Text='<%# Eval("product_id") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="商品图片">
<ItemTemplate>
<img src='<%# "../"+Eval("product_keywords") %>' width="50" height="45" border="0" onmouseover="mouse_0(this)"
onmousemove="mouse_1(this,event)" onmouseout="mouse_2(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="商品名称">
<ItemStyle Width="200px" />
<ItemTemplate>
<a href='#' target="_blank">
<asp:Label ID="Label2" runat="server"
Text='<%# Command.StringCut(Eval("product_title").ToString(),10)%>'></asp:Label>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
商品类型
</HeaderTemplate>
<ItemTemplate>
<%# Eval("producttype_title")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="案例介绍">
<ItemStyle Width="200px" />
<ItemTemplate>
<asp:Label ID="Label3" runat="server"
Text='<%# Command.StringCut(Eval("product_intro").ToString(),10)%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="product_time" HeaderText="添加日期" />
<asp:TemplateField>
<HeaderTemplate>
编辑
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="hlAdd" runat="server" NavigateUrl="ProductAdd.aspx">添加</asp:HyperLink>
<asp:HyperLink ID="hlModify" runat="server"
NavigateUrl='<%# "ProductAdd.aspx?pid="+ Eval("product_id") %>'>修改</asp:HyperLink>
<asp:LinkButton ID="lbDelete" runat="server"
CommandArgument='<%# Eval("product_id") %>' onclick="lbDelete_Click" ><span
onclick="return confirm('是否删除?')">删除</span></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
protected void SetProduct()
{
string strwhere = GetStrWhere();
string sql = "select producttype_title,product.* from producttype,product where producttype_id=product_type " + strwhere;
this.GridViewProduct.DataSource = CurrencyService.Query(sql);
this.GridViewProduct.DataBind();
}
这样绑定
AutoGenerateColumns="False" CellPadding="4" Font-Size="9pt" ForeColor="#333333"
GridLines="None" onpageindexchanging="GridViewProduct_PageIndexChanging">
<Columns>
<asp:TemplateField HeaderText="全选">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chbSelect" />
</ItemTemplate>
<HeaderTemplate>
<input type="checkbox" onclick="GetAllCheckBox(this)" />全选<asp:Button ID="btnalldel"
runat="server" Text="全部删除" Font-Size="8pt" Width="60px"
BackColor="AntiqueWhite" onclick="btnalldel_Click" OnClientClick="return confirm('确定全部删除吗?')" />
</HeaderTemplate>
<ControlStyle Width="50px" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblId" runat="server"
Text='<%# Eval("product_id") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="商品图片">
<ItemTemplate>
<img src='<%# "../"+Eval("product_keywords") %>' width="50" height="45" border="0" onmouseover="mouse_0(this)"
onmousemove="mouse_1(this,event)" onmouseout="mouse_2(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="商品名称">
<ItemStyle Width="200px" />
<ItemTemplate>
<a href='#' target="_blank">
<asp:Label ID="Label2" runat="server"
Text='<%# Command.StringCut(Eval("product_title").ToString(),10)%>'></asp:Label>
</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
商品类型
</HeaderTemplate>
<ItemTemplate>
<%# Eval("producttype_title")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="案例介绍">
<ItemStyle Width="200px" />
<ItemTemplate>
<asp:Label ID="Label3" runat="server"
Text='<%# Command.StringCut(Eval("product_intro").ToString(),10)%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="product_time" HeaderText="添加日期" />
<asp:TemplateField>
<HeaderTemplate>
编辑
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="hlAdd" runat="server" NavigateUrl="ProductAdd.aspx">添加</asp:HyperLink>
<asp:HyperLink ID="hlModify" runat="server"
NavigateUrl='<%# "ProductAdd.aspx?pid="+ Eval("product_id") %>'>修改</asp:HyperLink>
<asp:LinkButton ID="lbDelete" runat="server"
CommandArgument='<%# Eval("product_id") %>' onclick="lbDelete_Click" ><span
onclick="return confirm('是否删除?')">删除</span></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
protected void SetProduct()
{
string strwhere = GetStrWhere();
string sql = "select producttype_title,product.* from producttype,product where producttype_id=product_type " + strwhere;
this.GridViewProduct.DataSource = CurrencyService.Query(sql);
this.GridViewProduct.DataBind();
}
这样绑定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询