如果承保险种lblInsName这个值为“附加玻璃单独破碎险”或“附加不计免赔特约险”时,保额/责任限额(万元)tbInsured的值为零,并且不能输入,其余情况都有效,能输入。请问各位高手应该怎么做?在线等急<asp:datagrid id=insItemList runat="server" Width="100%" DataMember="InsuredItem" DataSource="<%# insurance %>" DataKeyField="TableName" GridLines="None" CellPadding="1" BorderWidth="2px" BorderColor="#0033CC" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle ForeColor="#0033CC" BackColor="#CCFF99"></AlternatingItemStyle>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="DimGray" BackColor="#CCFF00"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="TableName" ReadOnly="True" HeaderText="TableName">
<HeaderStyle Width="100px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="承保险种">
<HeaderStyle Width="120px"></HeaderStyle>
<ItemTemplate>
<STRONG><FONT color="#0000cc" size="1">
<asp:Label id=lblInsName runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.InsuranceName") %>'>
</asp:Label></FONT></STRONG>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="保额/责任限额(万元)">
<HeaderStyle Width="140px"></HeaderStyle>
<ItemTemplate>
<FONT face="宋体">
<asp:TextBox id=tbInsured tabIndex=23 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Insured") %>' Width="120px" MaxLength="8">
</asp:TextBox><SPAN style="COLOR: #ff0000"><%# (bool)DataBinder.Eval(Container.DataItem, "Required") ? "*" : "" %></SPAN>
<asp:regularexpressionvalidator id="premiumValidator" runat="server" ControlToValidate="tbInsured" Display="Dynamic"
ErrorMessage="保额数据无效!" ValidationExpression="\d{1,3}(?:(,\d{3})|\d)*([.]\d*)?"></asp:regularexpressionvalidator></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="保费(元)">
<HeaderStyle Width="140px"></HeaderStyle>
<ItemTemplate>
<FONT face="宋体">
<asp:TextBox id=tbPremium tabIndex=23 runat="server" Width="120px" Text='<%# DataBinder.Eval(Container, "DataItem.Premium") %>' MaxLength="8">
</asp:TextBox><span style="COLOR: #ff0000"><%# (bool)DataBinder.Eval(Container.DataItem, "Required") ? "*" : "" %></span>
<asp:regularexpressionvalidator id="Rglxpvldr17" runat="server" ErrorMessage="保费数据无效!" Display="Dynamic" ControlToValidate="tbPremium"
ValidationExpression="\d{1,3}(?:(,\d{3})|\d)*([.]\d*)?"></asp:regularexpressionvalidator></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="优惠金额(元)">
<ItemTemplate>
<asp:TextBox id=tbPreferential tabIndex=23 runat="server" Width="120px" Text='<%# DataBinder.Eval(Container, "DataItem.Preferential") %>' MaxLength="8">
</asp:TextBox><span style="COLOR: #ff0000"><%# (bool)DataBinder.Eval(Container.DataItem, "Required") ? "*" : "" %></span>
<asp:regularexpressionvalidator id="Rglxpvldr1" runat="server" ErrorMessage="优惠金额数据无效!" Display="Dynamic" ControlToValidate="tbPreferential"
ValidationExpression="\d{1,3}(?:(,\d{3})|\d)*([.]\d*)?"></asp:regularexpressionvalidator>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

解决方案 »

  1.   

    DataSource="<%# insurance %>" 
    在codeBehind里做绑定。
    datasource=aaaa;
      

  2.   

    在DataGrid控件的DataItemBind事件中
    Label lblInsName = (Label)e.Item.FindControl("lblInsName");
    if(lblInsName.Text=="附加玻璃单独破碎险" || lblInsName.Text == "附加不计免赔特约险")
    {
       TextBox tbInsured= (TextBox )e.Item.FindControl("tbInsured");
       if(tbInsured.Text == "0")
       {
           控件在此设为无效。
       }
    }
    else
    {
        控件在此设为有效。
    }
    希望对你有所帮助。
      

  3.   

    you can write a function string GetInsured(string InsuranceName, string Insured)
    {
      if (InsuranceName == "附加玻璃单独破碎险" || InsuranceName == "附加不计免赔特约")
    return "0";
      else
    return Insured;
    }bool IsEditable(string InsuranceName)
    {
      if (InsuranceName == "附加玻璃单独破碎险" || InsuranceName == "附加不计免赔特约")
    return false;
      else
    return true;
    }<asp:TextBox id=tbInsured tabIndex=23 runat="server"  Text='<%#  GetInsured(DataBinder.Eval(Container, "DataItem.InsuranceName").ToString(), DataBinder.Eval(Container, "DataItem.Insured").ToString()) %>' Width="120px" MaxLength="8" Enabled='<%# IsEditable(Container, "DataItem.InsuranceName").ToString()) %>'
    >
    </asp:TextBox>
      

  4.   

    DataItemBind事件中
    Label lblInsName = (Label)e.Item.FindControl("lblInsName");
    if(lblInsName.Text=="附加玻璃单独破碎险" || lblInsName.Text == "附加不计免赔特约险")
    {
       TextBox tbInsured= (TextBox )e.Item.FindControl("tbInsured");
       if(tbInsured.Text == "0")
       {
           控件设为无效。
       }
    }
    else
    {
        控件设为有效。
    }
    还有就是这个事件,也可以在HTML中调用,也可以直接在某些方面.cs文件中调用。
    在HTML中的调用方法:
    <asp:DataGrid id="dg" runat="server" DataItemBind="dg_DataItemBind()" />