.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

checkboxlist save check items to SQL (not concatenate)

Posted By:      Posted Date: October 20, 2010    Points: 0   Category :ASP.Net

I search through the web and I only found out how to concatenate.

I have a checkboxlist that is a list of Authors, it is included in my ADD BOOK form. Take note that a book can have many author so I need checkboxlist.

Instead of having this in my SQL table.

Table 1: Book

Book_ID      Book_Title       Book_Author

1                 My Book          Mark, Mike, John  <-- Concatenate

I need this.

Table 1: Book

Book_ID      Book_Title        Book_Author

1                 My Book            Mark

1                 My Book            Mike

1                 My Book            John

It's required that for one row there's only one author but it can have the same book id and title.

My current code

string add = "insert into Book values (@booktitle, @author);
SqlCommand cmd = new SqlCommand(add, con);
cmd.Parameters.Add("@booktitle", SqlDbType.NVarChar).Value = booktitle.Text;

View Complete Post

More Related Resource Links

How to apply color to selected number of items in check box list and drop downlist

Hi all,    I want to apply color to selected number of items in checkbox list and seleted number of items in drop downlist for e.g color red for few items and black (default). I have a bit value set in data base so if bit is set to 0 then red and if 1 then back. Please help me.  

CheckBoxList - save values to SQL

Hi, I have a checkboxlist on a c# page where when a box is checked it saves its value in the following format to a textbox 1,2,3, etc...  String values = ""; for (int i=0; i< cbl.Items.Count; i++) { if(cbl.Items[i].Selected) { values += cbl.Items[i].Value + ","; } } values = values.TrimEnd(','); This works ok however the problem is i want to be able to audit the values i save in the DB. For example i may want to do a count how many times 1 appears or 2 etc.. What is the best way to do this? Thanks 

Apply Style to checkboxlist Items


Hi ,

How to change colour of CheckBoxList Items Text ?

Ex: chkblstRoleFunc1.Attributes.Add("style", "color:red");

But For above ex, red colour is applied to the Text of all the Items of CheckBoxList. I want it to be applicable for only one Item among all the Items i.e. Red Colour for only one Item and rest all Items in Black Colour(which is the default colour).

Please view the following code that I have Impemented. Is It RIGHT ??
            To change I have to call javascript runtime on CheckBoxList OnLoad event.
Problem is that, below written call to Javascript is not Working.
Please have a look at the below given code :

1) Code Behind :-

if (ds1.Tables[0].Rows.Count != 0)

for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
chkblstRoleFunc1.Items.Insert(i, new ListItem(ds1.Tables[0].Rows[i].ItemArray[3].ToString(), ds1.Tables[0].Rows[i].ItemArray[1].ToString()));

if (Convert.ToInt32(ds1.Tables[0].Rows[i].ItemArray[2]) == 0)
chkblstRoleFunc1.Attributes.Add("onload", "javascript:setCheckboxColor('" + ds1.Ta

Check to see if items do not exist


I basically have 3 queries that I need to run to provide specific answers to my users.  Whether the machine is Running(Deployed), Not Running(Available) or "In Maintenance"(Unavailable).  The first and third queries run fine.  However the second one (in Bold)is where I'm having additional trouble, it needs to check to see if the Machine is "In Mainenance" or not.  If it is not in mainenance then it should get its value from the Designated amounts Table, Else it should give the value of '0'

Problem Query

"Not Running" but able to if needed.
Needs to check to determine if it is Available(i.e. Not Running) ("SELECT  TOP (1) CASE WHEN V300938F <= '.1'") it then needs to check to see if it matches this Criteria  "WHERE   (dbo.Designated_Amount.Unit_Code = '114') AND SIMS.Event_Type in ('IR','ME','MO','PE','PO','RU','SF','U1','U2','U3') AND (dbo.SIMS.EventEndTS IS NULL) AND (dbo.SIMS.Avail_Cap = 0)" then it should return a '0', if it doesn't match the Where clause it should return the value from the Designated_Amounts table.

declare @Amount float

select top 1 @Amount =  CAST(dbo.Designated_Amount.Amount AS Float)

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

jQuery: Styling DropDownList Alternating Items (Rows)

In the following example, I will show how you can style any asp:dropdownlist very easily.

The example demonstrates how you can change alternating row items background color, using the fadeTo() to add a nice touch in the dropdownlist. You can change alt rows with a couple lines.

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.

Hide a repeater in ASP.NET C# if the DataSource contains no items?

I have an ASP.NET page that uses a repeater nested within another repeater to generate a listing of data. It's to the effect of the following:
In the (C#) code-behind I'm basically using LINQ to pull a listing of information from an XML document and bind that information to the first repeater.

Searching for the answer to this, it seems the method is to determine whether the data for the nested repeater is empty. If it is, then you set the visibility of the repeater to false.

Creating SharePoint items with CreateItemActivity

Instead of creating new list items from code in your workflow you can use CreateItemActivity. CreateItemActivity can be used for creating list items or files. Properties of interest for this activity are the following (most of them are self-explanatory):

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

HttpContext.Items and Server.Transfer/Execute

The problem was basically that when a Server.Transfer call was applied the script container (and also various ClientScriptProxy script embedding routines) would potentially fail to load up the specified scripts.

Save images to SQL CE

Storing binary objects (such as image, office document etc.) into database is a little cumbersome when it comes to retrieval. Hence the most commonly accepted way is only store the file path in the database, and to store the documents on a file share.

Get pixel format, raw format, property id list and property items image in VB.net - C#.net.

n this simple article you will learn that how we can get pixel format, raw format, property id list and property items image in VB and C#.net.

Get Pixel Format:

Image consists of pixels to get the format of the pixel we have a property named pixel format. This property returns an enumeration of pixel format. This enumeration tells the pixel format.

To demonstrate make a window application. Drag one button and a picture box on form.

Now write the following code on Button click event:

check box control


Hi ,

I have a three check box in my web form ,i need to choose only one check box, if i choose one check box

another 2 check box automatically unchecked

can i use jquery for check box

I thought this would be simple... Trying to create a login does an ajax check before submit


I have the standard .net login control that is working.  (Still learning .net after 15yrs of classic)

What I want to do is OnButtonClick run a javascript function (to do an ajax call to the db to check if login is valid or not) and if it returns true, then submit the form normally, else don't submit. The piece that I can't figure out, is how to correctly override the default click even to hit my JS routine and then submit the form properly afterwards.

Thanks ahead of time

ListViewControl - how to group items by their value, for eg. date range



I have a table containing courses, columns are 

Name - "Yoga Classes"

DateStart - "2/23/2010"

DateEnd - "2/24/2010"

I am using ListView Control to bind it, is there a way to display them and group them by Month? 

for eg.


Piano Class (10th Jan 2010 - 11th Jan 2010)
Guitar Class (10th Jan 2010 - 11th Jan 2010)


Yoga Class (15th Feb 2010 - 16th Feb 2010)

Thanks for help.

Adding new items to a Repeater control with transitions?



I am currently in the process of writing a facebook type 'activity feed' for a site. Currently I am binding the last 10 items to a repeater control, which contains a usercontrol representing each item. This works fine but there are a couple of requiremnts that are giving me problems and wondered if the the good people of the forum could make some suggestions.

The requirement is that when a user clicks a refresh button any new events are added to the top of the list, the previous items drop down and the equivalent number of old items drop off the bottom, all with nice slider transitions.

I have put the repeater inside of an update control and are able to handle the transitions by using RegisterStartup script to drop jquery calls onto the page for the slider. However I cannot find a way to dynamically add or remove new datarows to the repeater. I need the old items to stay in the repeater and be pushed down by the new items, so completely refreshing the datasource seems like a bad idea.

I was thinking about maybe storing the datasource in the viewstate and adding rows to that, maybe with an extra column on the end which stores what transition is needed on the databind for my jquery, but there will be a 'View more items' link at the bottom of the page, so I am worried that the list could get pretty large and there

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend