.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 embedded in FormView InsertItemTemplate problem

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

I've searched hi/lo and found many similar posts but those answers aren't working for me.

I've got a FormView, in an UpdatePanel.  In the FormView's EditItemTemplate and InsertItemTemplate I'm using both a CheckBox and a CheckBoxList.  To present the data I databind in the code behind, (but then have to iterate to mark selected).  There I cast the sender as CheckBoxList in the OnPreRender event and use that object. 

The problem is retrieval.  I'm trying to access the user's entries when they submit by using the cast.  It is working fine for the CheckBox, but for the CheckBoxList the resulting checkboxlist object doesn't have any items. 

Here, both active and roles are created (they're not 'null') and active has the expected 'name' and 'selected' values, but roles has an item count = 0 and the for loop isn't entered.


            CheckBox active = ((CheckBox)Emp_Form.FindControl("cbActive"));

            CheckBoxList roles = (CheckBoxList)Emp_Form.FindControl("UsrRoles");

            foreach (ListItem role in roles.Items)
                // do stuff


Is there another way to cast a checkboxlist?  Any help would b

View Complete Post

More Related Resource Links

checkboxlist full post back problem is association with PopupControlExtender


I have used a checkboxlist in association with PopupControlExtender. All the items are inside the update panel. I used the server side SelectedIndex changed event of checkbox list for another purpose.  But it cause full post back while checking the check box item. The update panel doent make any sense here.

        <asp:ScriptManager ID="Scriptmanager1" runat="server">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">

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

Referencing Parent FormView from Embedded FormView

Looking for some direction here.  Thanks in advance for any assistance.   I have a scenario where I have a FormView positioned inside another FormView.  Each FormView is connected to a strongly typed ObjectDataSource (DataObjectName).  The parent FormView is a single record in Read Only mode.  The child FormView is defaulted to Insert Mode.  Can someone tell me how to get the Key Field (and even some of the other fields) from the parent FormView to use during Insert in the Child FormView?  I've tried using a combination of the different events (i.e. OnDataBind, OnInserting, etc.) on the child FormView.  This seems like it should be real simple but I'm just not getting it.   My structure looks as follows:<asp:objectdatasource id="vendor" dataobjecttypename="Vendor"... /> <asp:objectdatasource id="inquiry"... dataobjecttypename="Inquiry" ... /> <asp:FormView datasourceid="vendor" ...> ... <asp:FormView datasourceid="inquiry" ...></asp:FormView> ... </asp:FormView>   Tony

FormView custom data binding problem

Hi there,   I'm using VWD 2010 ASP.NET 4.0 and SQL Server 2008 Also I have login page with the ASP.NET configuration   one of my page has FormView with Update feature   Evryting works fine user login go to my FormView page and update the record.   Now I created a simple function   Protected Function GetUserName() As String        Return User.Identity.Name    End Function   and one of my coloumn call EditedBy   I replaced the Bind("EditedBy") field binding with   Custom binding GetUserName()   When user update it show the current user login name on the screen But it won't show in the table itself (it show null value when i do select statement)   I used to do this with ASP.NET 2.0 with no problem?   How do I fix that?   Thanks, Oded Dror  

In formview changingMode problem....

Hi... i am having insertpage.aspx where i am fetching systemdate but when i am changingMode in for data Insert, systemdate not showing that time and same as EditMode also. I am sending codebehind code .....please help me out..... /*********************************************************/ using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using VehicleApp.library; public partial class InsertPage : System.Web.UI.Page {     library lib = new library();     protected void Page_Load(object sender, EventArgs e)     {         if (!IsPostBack)         {             BindFormView();             Label mydate = (Label)VehicleFormView.Row.FindControl("dateLabel");             mydate.Text = DateTime.Now.Date.ToShortDateString();         }     }     private void BindFormView()     {         if (Session["strTemp"] != null)  &nb

Help with checkboxlist in formview edittemplate data display



I can insert a checkboxlist selected value as comma delimited string into the database. But I have hard time to reload it in formview edit mode.  I added a hidden label to retrieve the comma delimited string and try to use checkboxlist databound event, but it doesn't work. I don't know what problem is in my code. Please help me:

protected string sessiontypestr = string.Empty;

protected void chkType_DataBound(object sender, EventArgs e)
            CheckBoxList c = (CheckBoxList)FormView1.FindControl("chkType");
            if (c != null)

                Label test = (Label)(FormView1.FindControl("lblhiddensessiontype"));
                sessiontypestr = test.Text;

                string[] items = sessiontypestr.Split(',');

                for (int i = 0; i < c.Items.Count; i++)
                    if (items.Contains(c.Items[i].Value))
                        c.Items[i].Selected = true;


<asp:CheckBoxList ID="chkType" runat="server" Font-Size="Smaller" 
                SelectedValue='<%# Bind("session_type") %>' 

RequiredFieldValidator problem with FormView


I'm using a formview to insert a new record in my database (beta 2).
Everything works fine until I add a requiredfieldvalidator to validate the content of a textbox (bound to one of the parameter of the datasource) in the insertitemtemplate.
With the validator on the page, the page just posts back and nothing happens.
The problem does not appear when I use another type of validator (or no validators at all)

It seems that the validation event fires again on the postback just before the content of the textbox is retrieved (from the viewstate I suppose).
Here's my code.

<asp:FormView ID="fvMessage" runat="server" DataSourceID="odsMessages" OnItemInserting="fvMessage_ItemInserting"  DefaultMode="Insert">
        <table border="0">
                    <asp:Localize runat="server" Text="<%$Resources:Glossary,Recipient %>" />&nbsp;:</td>

Problem with checkboxlist, SQLDataSource



I am having some trouble getting a SPSqlDataSource to work, i've used this class plenty of times before and never ran into this problem before. The annoying thing is that i got it to work, no problems at all. So a keeped on writing a few lines of code, and when i ran the code, the page errored. No big deal, so i commented out all the code i writen after when i got it to work, and was quite surprised when the same error appeared, even though the same code worked previously.

So, here is the code:

 SPSqlDataSource GroupMembers = new SPSqlDataSource();
  GroupMembers.ConnectionString = "Data Source=SBSHP\\SHAREPOINT;Initial Catalog=WSS_Content_adfb096a-dfdb-4a41-a71f-a8debd660e4b;User ID=CustomConnections;Password=hemligtlösenord";
  GroupMembers.SelectCommand = "SELECT * FROM CustomGroupsMembers WHERE ID = '" + DropDownList1.SelectedValue + "'";
  CheckBoxList1.DataSource = GroupMembers;
  CheckBoxList1.DataTextField = "ID";
  CheckBoxList1.DataValueField = "ID";

And this is what the design looks like:

<asp:SqlDataSource runat="server" id="SqlDataSource1" ProviderName="System.Data.SqlClient" ConnectionString="Data Source=SBSHP\SH

Connection problem when connecting from windows service in Windows 7 embedded


Hi everyone

I'm trying to migrate our applications working with SQL Server 2005 Express from Windows XP to Windows 7, and have following problem. Desktop applications connect to SQL Server fine, but windows service app returns following error when trying to connect: [DBNETLIB][ConnectionOpen (SECCreateCredentials()).]SSL Security error

I tried installing service under localsystem account and under desktop user account with no success.

My connection string looks like Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=user;Initial Catalog=data;Data Source=servername

I've searched a bit about this error and one recommendation was to try to use SQL Native client, so I tried to change my connection string to

Provider=SQLNCLI;Pwd=password;UID=user;Database=data;Server=servername, this also works when running from desktop but when running from windows service I get another error

SQL Network Interfaces: The requested security package does not exist

This seems to be purely client problem because when I use wrong server name I still get the same errors.

I guess something changed with permissions of services in Windows 7

Any ideas what could be wrong and how to fix it?

Problem to group radio button across gridview rows

In general no one can easily group or make a single selection from radio button list inside gridview rows. There are a lot of way to make a single or unique selection from list. Here i want to share how i can address this problem in the most easiest way. Googling the problem most of the cases i saw the grouping in horizontal way. Thats why i tried to group the radio buttons in vertical manner. Let i have a requirement like below:

Regrading Sharpoint 2010 problem and solutions

We can write your question and problem on this blogger.you get ans.use.

This sharpoint 2010 problem solving threads

Hi friend,

you can use this thread to solving problem and solutions.

Virtual Path Problem


 I get the following error on last line below (working on remote host): 'E:\web\sfcascom\ls_admin/uploads/images/001.JPG' is not a valid virtual path,

Note that the slashes go in different directions

I've tried a number of things but nothing seems to work. Thanks-


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Web.UI.WebControls

Imports System.Drawing.Imaging.ImageCodecInfo
Partial Class Protected_imageupload
    Inherits System.Web.UI.Page
    Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        ' Initialize variables
        Dim sSavePath As String
        Dim sThumbExtension As String
        Dim intThumbWidth As Integer
        Dim intThumbHeight As Integer
        Dim sFilename As String = ""
        ' Set constant values
        'sSavePath = "images/"
        sSavePath = Server.MapPath("~/") + "ls_admin/uploads/images/"

        sThumbExtension = "_thumb"
        intThumbWidth = 160
        intThumbHeight = 120

        ' If file field isn?t empty
        If FilUpload.PostedFile IsNot Nothing Then
            ' Check file size (mustn?t be 0)
            Dim myFile As Http

Strange Photo upload problem


I'm working project it's live on shared hosting

we'er uploading photos to a file on the server everything works fine the photo is resized renamed and sent to the folder

the upload page returns the thumbnail and the full size photo it's there all the photos have to be approved by an admin

twice now after they have been approved they disapear I checked the folder they are not there could there be anywhere

on the server they could get hung up before they go into the folder I have it setup so when you delete the data base entry it deletes the photo from the folder othe than that you need to open the folder and delete the photo this has hapened twice now I tried to recreate it with no luck

thaks for your help in advance

ASP.Net Caching problem ??


I'm having a problem with an asp.net 3.0 application using a gridview to display data.  The problem seems to be that despite a brand new .selectCommand being sent to the sqlDataSource, the gridview starts displaying data from *someone else's* query.  For example, user A is logged in and will be working fine until a few page submissions later when the gridview data starts suddenly showing information that belongs to another user. 

This is my first asp.net application, though I've been working with classic asp and ADO for years so I'm used to sending a SQL string and getting back the results from that string.  Apparently there is a complex caching system which is interferring which I do not at all understand so at this point I just want to stop the server from caching any data whatsoever.  Is this possible?

Any and all help will be much appreciated!!

Could some one tell me whats the Problem with this String Manipulation ??? C#.net



I store some values from code behind to a label which is Hidden !

<asp:Label ID="lbl_Hidden" runat="server" Visible = "false"></asp:Label>

and at the page load event i retrieve the value of the label & assign it to a string !

stringvalue = lbl_Hidden.Text;

Now i dont know why this manipulation does'nt work !

I've a character 'A' in the string and i'm unable to replace it with a space !

stringvalue.Replace(A, " ");

Wot do u think abt it ????

Formview LinqData source not allowing updates


OK, I'm confused.  I've set up a formview with a Linqdata source to allow users to edit records.  When I run it, edit data and submit, it blows up and tells me "Linq datasource6  does not support the Select property when the Delete, Insert or Update operations are enabled."  I googled that warning and saw a couple of posts on this forum saying the problem is the slect statement has to be removed from the Linq data source for it to allow updates. 

But if I remove the select statement then how do I show the user specific info on pageload?   plus I thought the two way databind was an advantge of the datasource control.




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