请问:怎么获取DATAGRID中的值?
我想根据DATAGRID中绑定的控件,在ItemDataBound事件中,
判断某控件绑定的数据是否有值,如果没有值的话,则隐藏,显示另一控件.
如果有值,则显示该控件,隐藏其它控件.
我现在的错误是,我所绑定的控件LBLCHN.Text取到的值始终为空,大家帮忙看看哪里有错?
HTML 中的代码如下:
<asp:TemplateColumn>
<ItemStyle Wrap= "False " Width= "16% " CssClass= "cell_grid " <ItemTemplate> <asp:Label Runat= "server " ID= "LBLCHN ">
<%# DataBinder.Eval(Container.DataItem, "CustomerCHN ") %>
</asp:Label>
<asp:Label Runat= "server " ID= "LBLLM ">
<%# DataBinder.Eval(Container.DataItem, "CustomerLM ") %>
</asp:Label>
<asp:Label Runat= "server " ID= "LBLKATA ">
<%# DataBinder.Eval(Container.DataItem, "CustomerKATA ") %>
</asp:Label>
<asp:Label Runat= "server " ID= "LBLCP ">
<%# DataBinder.Eval(Container.DataItem, "CompanyID ") %>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
------------------------------------------
VB中的代码如下:
在dg_Master_ItemDataBound事件中
Dim LBLCHN As Label = DirectCast(e.Item.FindControl( "LBLCHN "), Label)
Dim LBLLM As Label = DirectCast(e.Item.FindControl( "LBLLM "), Label)
Dim LBLKATA As Label = DirectCast(e.Item.FindControl( "LBLKATA "), Label)
Dim LBLCP As Label = DirectCast(e.Item.FindControl( "LBLCP "), Label)
If Not LBLCHN.Text.ToString.Trim().Equals(String.Empty) Then '客氏名(字)
e.Item.FindControl( "LBLCHN ").Visible = True
e.Item.FindControl( "LBLLM ").Visible = False
e.Item.FindControl( "LBLKATA ").Visible = False
e.Item.FindControl( "LBLCP ").Visible = False
Else
If LBLLM.Text <> " " Then '客氏名(ロマ)
e.Item.FindControl( "LBLCHN ").Visible = False
e.Item.FindControl( "LBLLM ").Visible = True
e.Item.FindControl( "LBLKATA ").Visible = False
e.Item.FindControl( "LBLCP ").Visible = False
END IF
END IF
[解决办法]
<asp:Label Runat= "server " ID= "LBLCHN ">
<%# DataBinder.Eval(Container.DataItem, "CustomerCHN ") %>
</asp:Label>
----------------------
应该是这样绑定的, <asp:Label Runat= "server " ID= "LBLCHN " Text= ' <%# DataBinder.Eval(Container.DataItem, "CustomerCHN ") %> '> </asp:Label>
你其他的Label都绑定错了,