DataGrid模板列的问题
在DataGrid有两个模板列
一个是Imagebutton,一个是Label,我想点击Imagebutton的时候,取出Label的Text
具体代码如下:
<asp:datagrid id="SearchGrid" runat="server">
<Columns>
<asp:TemplateColumn Visible=false>
<ItemTemplate>
<asp:Label ID="Store"><%# DataBinder.Eval(Container.DataItem,"StoreID")%></asp:Label>
<asp:Label ID="Product"><%# DataBinder.Eval(Container.DataItem,"ProductID")%></asp:Label> </ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton ImageUrl='../Image/buy.gif' runat="server" ID="buy" OnClick="ImageButton_click">
</asp:ImageButton> </ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
//Imagebutton事件
public void ImageButton_click
(object sender,System.Web.UI.ImageClickEventArgs e)
{
string StoreID,ProductID;
foreach (DataGridItem DataRows in SearchGrid.Items)
{
ImageButton AddCart = (ImageButton)DataRows.FindControl("buy");
if(AddCart.Equals((ImageButton)sender))
{
Label Store = (Label)DataRows.FindControl("Store");
StoreID = Store.Text; //这里出错,未将对象引用设置到对象的实例。
Label Product = (Label)DataRows.FindControl("Product");
ProductID = Product.Text;
}
}
}
1、Imagebutton可以找到,为什么Label找不到?
2、ImageButton AddCart=(ImageButton)DataRows.Cells[x].FindControl("buy");
Cell后面是0或者1都可以找到Imagebutton,为什么?
一个是Imagebutton,一个是Label,我想点击Imagebutton的时候,取出Label的Text
具体代码如下:
<asp:datagrid id="SearchGrid" runat="server">
<Columns>
<asp:TemplateColumn Visible=false>
<ItemTemplate>
<asp:Label ID="Store"><%# DataBinder.Eval(Container.DataItem,"StoreID")%></asp:Label>
<asp:Label ID="Product"><%# DataBinder.Eval(Container.DataItem,"ProductID")%></asp:Label> </ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:ImageButton ImageUrl='../Image/buy.gif' runat="server" ID="buy" OnClick="ImageButton_click">
</asp:ImageButton> </ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
//Imagebutton事件
public void ImageButton_click
(object sender,System.Web.UI.ImageClickEventArgs e)
{
string StoreID,ProductID;
foreach (DataGridItem DataRows in SearchGrid.Items)
{
ImageButton AddCart = (ImageButton)DataRows.FindControl("buy");
if(AddCart.Equals((ImageButton)sender))
{
Label Store = (Label)DataRows.FindControl("Store");
StoreID = Store.Text; //这里出错,未将对象引用设置到对象的实例。
Label Product = (Label)DataRows.FindControl("Product");
ProductID = Product.Text;
}
}
}
1、Imagebutton可以找到,为什么Label找不到?
2、ImageButton AddCart=(ImageButton)DataRows.Cells[x].FindControl("buy");
Cell后面是0或者1都可以找到Imagebutton,为什么?
...全文
相关推荐
NET CF下DataGrid数据行颜色交替
.NET CF下DataGrid数据行颜色交替
c# WPF DataGrid 底部汇总行合计
DataGrid 统计每一列的值,合计在底部。 这里的合计是在 DataGrid 的内部,汇总在最后一行,在 DataGrid 横向滚动条的上方进行汇总。
WPF DataGrid:对自动生成的列启用可空类型的标准排序
DataGrid不会在自动生成的列上对可为空的值类型进行排序。
wpf datagrid 单元格颜色 根据条件改变颜色 例子
wpf datagrid 单元格颜色 根据条件改变颜色
DataGrid控件高级使用
DataGrid控件高级使用 DataGrid控件高级使用



