<EditItemTemplate> <asp:Label id="labelid" Text= '<%# DataBinder.Eval(Container.DataItem,"id") %>' runat="server" Visible="false"/> <asp:Label id="labelnx" Text= '<%# DataBinder.Eval(Container.DataItem,"nx") %>' runat="server" Visible="false"/> <table width="240" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="22"><FONT COLOR="black">货号:[
<asp:Label id="type" Text= '<%# DataBinder.Eval(Container.DataItem,"type") %>' runat="server"/>]
<asp:Label id="code" Text= '<%# DataBinder.Eval(Container.DataItem,"code") %>' runat="server"/></FONT></td>
</tr>
<tr>
<td height="22"><FONT COLOR="black">单价:¥
<asp:Label id="price" Text= '<%# DataBinder.Eval(Container.DataItem,"price") %>' runat="server"/>元</FONT></td>
</tr><tr> <td height="22">&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="howmany" Runat="server" BorderStyle="Groove" TextMode="SingleLine" Width="40" Height="20px">1</asp:TextBox>
<asp:button id="updateincart" runat="server" CssClass="hand" Height="20px" Text="确定" BorderStyle="Outset" CommandName="update" /> <asp:button id="canceledit" runat="server" CssClass="hand" Height="20px" Text="取消" BorderStyle="Outset" CommandName="Cancel" /><br> <asp:TextBox ID="ring" Runat="server" BorderStyle="Groove" TextMode="SingleLine" Width="200" Height="20px" Visible="False" /> </td> </tr></table> </EditItemTemplate>
private void dlsp_EditCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (Session["user"]==null)
{
firstbind();
}
else
{
string typedit = ((Label)e.Item.FindControl"typedit")).Text;
dlsp.EditItemIndex = e.Item.ItemIndex;
typedit=typedit.Substring(2,2);
///////// ////////////请问如何在这里控制上面id=ring的TextBox控件visible属性////////////// if(typedit=="er")
{
.Visible = true;
}
else
{
.Visible = false;
}
bind();
}
}

解决方案 »

  1.   

    TextBox txtring = (TextBox)e.Item.FindControl("ring");
    txtring.visible=true;呵呵,C#语法不太懂,如果哪里标点语法错误,你改一下,就是这样就可以了
      

  2.   

    这样不行的呀,这样是修改ItemTemeplate里控件的属性,并不是修改EditItemTemplate里控件的属性呀
      

  3.   

    bind();
    提到
    if(typedit=="er")
    {
    .Visible = true;
    }
    else
    {
    .Visible = false;
    }
    以前
      

  4.   

    如果你的typedit是ItemTemeplate里面的话代码修改如下
    string typedit = ((Label)e.Item.FindControl"typedit")).Text;
    typedit=typedit.Substring(2,2);
    dlsp.EditItemIndex = e.Item.ItemIndex;
    bind();
    if(typedit=="er")
    {
    ((TextBox)e.Item.FindControl("ring")).Visible = true;
    }
    else
    {
    ((TextBox)e.Item.FindControl("ring")).Visible = false;
    }
      

  5.   

    Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
            Select Case e.Item.ItemType
                Case ListItemType.Item, ListItemType.AlternatingItem
                    TextBox txtring = (TextBox)e.Item.FindControl("ring");
                    txtring.visible=true;
            End Select
        End Sub
      

  6.   

    还是不行吗,显示:
    异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。