0

I have an asp.net page that contain some textbox in ListView
I want to disable textbox that have some text by asp.net ItemDataBound ListView Event or Javascript code How can i do that?

<asp:ListView ID="ListView1" runat="server"  DataKeyNames="ID" >
    <ItemTemplate>
        <tr class="xl68" height="29" style='mso-height-source: userset; height: 21.75pt'>

        <td >&nbsp; <asp:Label ID="lblID" runat="server" Visible="false" Text='<%# Eval("ID") %>'></asp:Label></td>
        <td class="xl66" style='border-top: none'><%# Container.DataItemIndex + 1 %> </td>
        <td class="xl69" width="351" style='border-top: none; border-left: none; width: 263pt'> <%# Eval("Name") %></td>
        <td><asp:TextBox runat="server" MaxLength="2" Text='<%# Bind("C1") %>' ID="txb1"  ></asp:TextBox></td>
        <td><asp:TextBox runat="server" MaxLength="2" Text='<%# Bind("C2") %>' ID="txb2"  ></asp:TextBox></td>
        <td><asp:TextBox runat="server" MaxLength="2" Text='<%# Bind("C3") %>' ID="txb3"  ></asp:TextBox></td>
        <td><asp:TextBox runat="server" MaxLength="2" Text='<%# Bind("C4") %>' ID="txb4"  ></asp:TextBox></td>
        <td><asp:TextBox runat="server" MaxLength="2" Text='<%# Bind("C5") %>' ID="txb5"  ></asp:TextBox></td>
        <td class="xl67">&nbsp;</td>

        </tr>

    </ItemTemplate>
</asp:ListView>

3 Answers 3

1

add the CssClass property with every TextBox control like this

<asp:TextBox runat="server" MaxLength="2" ID="txb1" CssClass="myCss"  ></asp:TextBox>

add the Js function in aspx

 function DisableInput(){

     var inputs = $('input.myCss[type="text"]');
     inputs.each(function( index ) 
     {
       if( $( this ).text() !='')
       {
        $( this ).attr('disabled',true);
       }
     });

 }

On you Page_Load event add this code

ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:DisableInput(); ", true);
Sign up to request clarification or add additional context in comments.

Comments

0

On you Page_Load event add this code

ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:disablewithText(); ", true);

In that javaScript function you can iterate through all the textboxes and check for having value and accordingly you can set disable attribute.

Comments

0

I Solved it in CodeBehind by this code in Page_Load Event

foreach (ListViewItem row in ListView1.Items)
                    {
                        foreach (Control txt in row.Controls)
                        {
                            if (txt is TextBox)
                            {
                                if (((TextBox)txt).Text != "")
                                    ((TextBox)txt).Enabled = false;
                            }
                        }

                    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.