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


Top 5 Contributors of the Month
satyapriyanayak
SP
Sambanthamoorthy
Swati Kadam
rosgeppe
Post New Web Links

CheckBoxList - save values to SQL

Posted By:      Posted Date: September 15, 2010    Points: 0   Category :ASP.Net
 
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 


View Complete Post


More Related Resource Links

Problem getting values next to each other from two separate CheckBoxList controls

  
Hi, I am using three CheckBoxList controls in ASP.NET Wizard control. CheckBoxList controls: <asp:CheckBoxList ID="cblLondonDates" runat="server" DataSourceID="SqlDataSource1" DataTextField="ShowDate" DataTextFormatString="{0:G}" DataValueField="ShowDate" ForeColor="#333333" CssClass="ShowDateMargin"></asp:CheckBoxList> <asp:CheckBoxList ID="cblSingleL" runat="server" DataSourceID="SqlDataSource2" DataTextField="size8" DataValueField="size8" ForeColor="#333333"> </asp:CheckBoxList> <asp:CheckBoxList ID="cblHalfL" runat="server" DataSourceID="SqlDataSource2" DataTextField="size6" DataValueField="size6" ForeColor="#333333"></asp:CheckBoxList>   cblLondonDates chackboxlist control shows dates generated from SQL table. cblSingleL an cblHalfL show table sizes. On ASP page they come up as following: 12/03/2011(checkboxlist-ID="cblLondonDates")-Single(checkboxlist-ID="cblSingleL") - Half(checkboxlist-ID="cblHalfL") 03/03/2012(checkboxlist-ID="cblLondonDates")-Single(checkboxlist-ID="cblSingleL") - Half(checkboxlist-ID="cblHalfL") 05/10/2010(checkboxlist-ID="cblLo

Not able to save checkbox values as TRUE on record creation

  
I have a form I created in InfoPath 2010 on a SharePoint 2010 list. As part of this list, there are 6 yes/no columns.  Each yes/no column I have bound to a different checkbox in the InfoPath form.  In SharePoint, when I view the list and click "add new item", the blank InfoPath form appears, I edit the form and submit it.  All works fine.... EXCEPT the checkboxes.  It seems that the checkboxes always save as FALSE the first time I save a new record. If I save the new record, and then choose to "edit the item", I can set any or all of the checkboxes to true, and it works fine.  But on the initial creation of the record (using InfoPath), the checkboxes always end up being persisted as FALSE. If I create a new record directly in the list (using the datasheet view), I am able to save the yes/no fields as YES, and they persist.  So the problem really does seem to point to the InfoPath form. Any thoughts on how I can persist a TRUE value for these checkboxes when saving for the first time?

CheckBoxList in UpdatePanel won't change values

  
Hello all.  I have a CheckBoxList that contains the days of the week.  If I use standard asp.net with AutoPostBack = true, everything works fine.  However, I would like to not have post backs everytime a user selects a day, so I'm trying to get the control to update using Atlas.  Here is the code (note: I put in the asteriks to bypass the filters on this website):  <*atlas:UpdatePanel ID="validDaysUpdatePanel" runat="server" Mode="Always"> <*ContentTemplate> <*asp:CheckBoxList ID="cblValidDays" runat="server" CssClass="inputfields" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="cblValidDays_SelectedIndexChanged" > <*asp:ListItem Text="All" Selected="True"><*/asp:ListItem> <*asp:ListItem Text="Sun" Value="1"><*/asp:ListItem> <*asp:ListItem Text="Mon" Value="2"><*/asp:ListItem> <*asp:ListItem Text="Wed" Value="4"><*/asp:ListItem> <*asp:ListItem Text="Thu" Value="5"><*/asp:ListItem> <*asp:ListItem Text="Fri" Value="6"><*/asp:ListItem> <*asp:ListItem Text="Sat" Value="7"><*/asp:ListItem> <*/asp:CheckBoxList> <*/ContentTemplate> <*Triggers> <*atlas:ControlEventTrigger ControlID="cblValidDays" EventName="SelectedIndexChanged" /> <*/Triggers> <*/atlas:Upd

Save temporary values in gridview to database

  
Hi.I have a code here,where it will store temporary data in a gridview from textbox where when the data is stored temporarily in gridview.Alternately,it will be linked to search the word in google.Now i want to save the values in the gridview to database.I m new to asp.net,seeking ideas from all.Any ideas guys?Here is my .aspx code: <body> <div> <table > <tr> <td class="style1"> <asp:Label ID="Label1" runat="server" Text="Caller Info :"></asp:Label> </td> <td style="width: 100px"> <asp:TextBox ID="TxtName" runat="server" class="cls" onekeypress="" ToolTip="Press Enter key for new input"></asp:TextBox> </td> </tr> </table> <asp:Button ID="BtnAddToTable" runat="server" align="right" class="cls" Text="Add" OnClick="BtnAddToTable_Click" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" > <Columns> <asp:TemplateField HeaderText="Caller Information"> <ItemTemplate> <a onclick='document.getElementById("<%=iframe1.ClientID%>").src = this.href; return false

Insert checkboxlist selected values into sql table using createuser wizard

  

Hi,

I am using CreateUserWizard control where I collect personal information from the user on the first step (ie. name, address, tel, mobile etc) then on the second step I collect information for membership service (ie. user name, password, email etc). When user clicks Create button, information is sent to two different tables in the same database. Everything works fine but one.

In the first step where I collect personal information, I also collect details about Interest which is a CheckBoxList (CheckBoxList is getting values from Interests table: 1-White, 2-Green, 3-Brown, 4-Maroon, 5-Yellow).

What I want to do is, when client selects his itnerest categories and clicks Create button, to send selected values from CheckBoxList into the third table called Categories. I want values to be registered into the CatCode column in Interests table as comma delimited. For example: if client selected "White", "Green" and "Yellow", appropriate values for those interests (such as 1, 3, 5) to be registered under Categories table CatCode column (like: 1,3,5).

Following is my code:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
        oncreateduser="CreateU

Reading/storing values of checkboxlist in SQL (VB)

  

Hi there,

I'm trying to store multiple selected checkboxes from a single checkboxlist, but i don't know where to start.. Sealed
Imagine i have three tables: tbl_events, tbl_organisors and tbl_settings and i want to store the organisors of an event.

Each event can have multiple organisors, so each organisor should be added as a single row into tbl_settings.
I know how to bind tbl_organisors to a checkboxlist, but how do i store the results (meaning: add the rows to tbl_settings) ?

tbl_events: Event_ID (PK) and Event_Name
tbl_organisors: User_ID and user_name.
tbl_settings: Settings_ID (PK), Event_ID and User_ID

Checkboxlist:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SDS_Organisors"
DataTextField="User_Name" DataValueField="User_ID" RepeatColumns="2">
</asp:CheckBoxList>

SQLDatasource:

<asp:SqlDataSource ID="SDS_Organisors" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>"

Default Column Values in a Document Library (SP2010) do not show up in word 2010 until you save and

  

when you create a document in a SP 2010 document library (of a particular content type, by clicking new, letter (content type name) in sharepoint for example) which has default values set on in in the library (set by using library settings -> change default column values), the default values do not show up until you create the document , save it and reopen it again.  Is this a bug or by design.  If it is by design, it is horrible since if some of the column default values are mandatory in the content type then you actually have to type them in before you could possibly save the file which defeats the whole point of having default column values.  Also it is tremendously clunky for a user to have to create file, save it , close it, and reopen it just to view the default metadata in the document information panel that is supposed to be there.

Anyone have any thoughts/solutions to this problem?


krd

checkboxlist save check items to SQL (not concatenate)

  

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;
cmd.

Custom Form does not save values if field validation occurred

  

 

I have a custom New form that I am having problems with.  If a user inputs all fields, and the form validation doesn't catch any problems, then the list item is saved with no problems.  

 

If one of the form fields finds a problem such as a required field that wasn't entered or an invalid name in the people picker, then after the user corrects the problem and presses save the list item will get saved without the correct values from the form fields.  The form fields still display the correct information before pressing save, but the list item that was saved does not have the same values as the form fields.

 

It seems that SharePoint:FormField are fine, but things such as SharePointBig SmileVDropDownList will display the data after a form error, but will no longer keep the form data and therefore it doesn't get saved.

 

Has anyone else had this problem?  If so then have you found a fix?


Checking Some Values In A CheckBoxList In The Page Load Event.

  

Hello forum,

I have a checkboxlist (cblTeamMates) with a sqldatasource (sqlTeamMates) that has 3 columns (ID, FullName and Status ).  The datavaluefield and datatextfield for cblTeamMates is "FullName" and the 2 status values possible are "Available" and "Absent".  How do I go about, in the page load event,  checking all  the names (FullName) whose Status is "Available"?

Thank you.


Pass Checkboxlist control multiple selected values to SQL table

  

Hi,

I wanted to know if it is possible to pass multiple selected values from Checkboxlist to SQL table so each selections goes into separate row in the table.

I tried it using the following code (to pass ShowDate value) but it enters value only if I make one selection. It gives me an error message if I make two selections and try to pass it to SQL.

 

string showdate = string.Empty;

foreach (ListItem li in BirmShowDates.Items)
        {
            if (li.Selected)
            {
                showdate += li.Value;
            }
        }

            
            conn.Open();

            string sql = "INSERT INTO [BShow] ([Single], [UserId], [ShowDate], [Half]) VALUES (@Single, @UserId, @ShowDate, @Half) SELECT [Single], [UserId],  [ShowDate], [Half] FROM [BShow] WHERE [BShow].[ShowDate] = [BShow].[ShowDate]";

            SqlCommand cmd = new SqlCommand(sql, conn);

cmd.Parameters.AddWithValue("@ShowDate", showdate.ToString());

 cmd.ExecuteNonQuery();
 conn.Close();

Thank you.


How to save checkbox values into sql server 2005 via c#

  
Hi there

I want to know how I can save a checkbox value into sql server 2005?  The check box is in my windows forms application...

Thanks

How to Pass Values Between Web Pages ASP.NET

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.

How to Pass Values Between ASP.NET Web Pages

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.
Categories: 
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