Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/Time format & multiple selection with listbox problem in ASP.net

Status
Not open for further replies.

frmsasp

Programmer
Sep 2, 2005
9
IN
Hello there,

Currently I am working with the project which needs time format in 24 hours format(in ASP.net & C# langauges) and other features but i am facing problem with them. I have described the problems below in detail to easily understand, so please let me know if you know...

1> How to convert 10:30 pm into 22:30(24 hrs time format)?

2> I had used listbox with multiple selection for display of my item. Following is a example.
1. Item One.
2. Item Two.
3. Item Three.
4. Item Four.
5. Item Five.
Now at the time of record insertion I had select Item Two, Item Four, Item Five. In database I will store its ID with comma delimiter says 2,4,5.
Now in the edit form I want to display selectionbar on old previous item in listbox. so how shall I ?
I had used below code:
for (j=0; j < IdSplit.Length; j++)
{
LstBox.SelectedValue = IdSplit[j].ToString();
}
This will shows selectionbar on last id only. In our example it will shows selectionbar on Item Five, 5.

3> I had created checkbox dynamically with below statement FOR EACH Module.
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='A'>Add
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='E'>Edit
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='D'>Delete
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='S'>
Search Say my Module_Id = 12
After form submit, I got value by form.querystring["chk121"]; form.querystring["chk122"];
form.querystring["chk123"];
form.querystring["chk124"];
but I want to use foreach loop for checking of for loop. Because there are more then 50 modules. so how shall I do this ?

Any help, advice or pointers on this matter would be highly appreciated.

Thanks,
Paresh
 
1) You can use something like:
Code:
        Dim d As DateTime = "10:30pm"
        Dim s As String = d.ToShortTimeString()

2) Can you explain this again as I don't really understand your explanation of what you are trying to do

3) Why don't you use a CheckBoxList?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Dear friend,

Kindly thanks for your reply.

1. Well I know about VB.Net, but in C# it will not give time format in 24 hours. There is no function like ToShortTimeString() in C# or friend I don't have idea. So will you please tell which function or method I have to use with C#.

2. Second problem solved by me.

3. Regarding third poing, you are right that we have to use CheckBoxList. But in my case, checkbox is generated dynamically. So I can't use CheckBoxList.

Do you have any idea how to created CheckBoxList dynamically. Plus I have to keep this checkbox in Tree format. That's why I have used HTML checkbox with label control.

Once again thanks,


Jeenec
 
1) There is a ToShortTimeString property for a DateTime value. This seemed to work for me:
Code:
DateTime dt = DateTime.Now;
String s = dt.ToShortTimeString();

3) I don't undertand why you can't use a CheckBoxList and simply add items to it as you need them i.e.
Code:
CheckBoxList1.Items.Add("Item1");
CheckBoxList1.Items.Add("Item2");
CheckBoxList1.Items.Add("Item3");


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hello there,

Currently I am working with the project which needs dynamically generated checkboxes and i have generated dynamic checkboxes but i am facing problem with getting the vaue of selected checkboxes.

Problem is described below in detail to easily understood, so please let me know if you come to know...

Example:
I am creating a form to assign rights to site admin for managing different module of the site from back end. Please have a look at attached file to better understand the structure of admin rights form which i used.

I had created checkbox dynamically with below statement FOR EACH Module.

lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='A'>Add
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='E'>Edit
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='D'>Delete
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='S'>Search

Say my Module_Id = 12

After form submit I got value with
form.querystring["chk121"]; form.querystring["chk122"];
form.querystring["chk123"];
form.querystring["chk124"];

But I want to use foreach loop for getting the values of each selected checkboxes Because there are more then 50 moudles. so please,let me know how to do this? Main problem is that I don't know how many total checkbox generated dynamically, that is why I have to use foreach or for loop.

Any help, advice or pointers on this matter would be highly appreciated.

Thanks,
Paresh
 
Since your controls are created dynamically you have to loop through the conrols on the page and check for the type of control, then cast and grab the control's value. See this thread:

thread855-1136177

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top