-1

Hi...
M working with ListBox Control in aspx.cs.
Can AnyOne help me out regarding....How to ensure that atleast one item gets selected in a listbox before button click event gets fired when button is clicked???
Thanks in Advance.....

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by Kusno
0

Can u tell me which properties to be set for required field validator so as to accomplish the thing.....

0

ControlToValidate property,

<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ErrorMessage="(required)" ControlToValidate="ListBox1"></asp:RequiredFieldValidator>
0

Thanks for u Support...
But my problem is....
i hav 2 listboxes...
1st got populated with some items....
when i click button1,selected items in listbox1 got populated in to
listbox2...&& finally if i click button2,the selected items in listbox2 get in touch with datagrid logic......
here i m struck ensuring atleast one item shuld get selected in listbox2....if not,whenever i click button2(with out selected items) m gettin error....
&&
i already used required field validator for listbox2....but its gettin fired when i clicking button1...

1

hi..

If ListBox1.SelectedIndex < 0 Then            
      Exit Sub
 End If
0

yeah.....but mine is c#......
so do u mean that i need to exit from the button click event???
How??/

0

hi..

If ListBox1.SelectedIndex < 0 Then            
      Exit Sub
 End If

yeah.....but mine is c#......
so do u mean that i need to exit from the button click event???
How??/

If you don't use "exit sub", it will continue until "End Sub"
but, at least, you can give a message to the user

If ListBox1.SelectedIndex < 0 Then   
      LbMsg.Text = "No Record is selected."         
      Exit Sub
 End If
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.