473,779 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating GridView EditItem textbox with popupextender panel checkboxlist values

5 New Member
I dont know if this kind of issue has been addressed earlier.

I have a gridview control on a form, in the EditItem Template when a textbox is clicked, I have a popupcontrolext ender displaying an AP Panel which contains

a checkboxlist and two buttons "OK" and "Cancel". What I want to do is, after the selections are made and after the "OK" button is clicked I want to display

the selected items of the checkboxlist seperated by commas, (ex, French, English, German) in the textbox which was the targetcontrol of the popupextender.

I have the following code
Expand|Select|Wrap|Line Numbers
  1. <EditItemTemplate>
  2. <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("LanguagesKnown") %>'></asp:TextBox>
  3.  
  4. <cc1:PopupControlExtender ID="PopupControlExtender2" runat="server"
  5. TargetControlID="TextBox2" PopupControlID="Panel1" Position="Bottom"
  6. CommitProperty="Value" CommitScript="e.Value">
  7. </cc1:PopupControlExtender>
  8.  
  9. <asp:Panel ID="Panel1" runat="server" CssClass="popupControl" >
  10.  
  11. <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="AccessDataSource2" AppendDataBoundItems="True" DataTextField="LanguagesList" 
  12.  
  13. AutoPostBack="False">
  14. </asp:CheckBoxList>
  15. <asp:Button ID="Button2" runat="server" Text="OK" UseSubmitBehavior="True" />
  16. <asp:Button ID="Button3" runat="server" Text="Cancel" UseSubmitBehavior="False" />
  17. </asp:Panel>
  18.  
  19. </EditItemTemplate>
  20.  
I would appreciate if someone get help me out in achieving my objective.

Deepak Jadhav
Jan 28 '09 #1
5 7746
Frinavale
9,735 Recognized Expert Moderator Expert
In the "Ok Button" Click Event, display the selected items of the CheckBoxList separated by commas, in the TextBox....
Jan 30 '09 #2
deepakthegeek
5 New Member
Frinavale, what you have replied to is exactly my question. If I knew how I could have done that I would have never posted my question. BTW the "OK" button will not have an OnClick event since it is placed inside the ASP panel which in return is placed inside the EditItem template of the GridView.

I know for sure know that it has to be handled by a javascript function on the client side. My question is "How will I do it?" "How will I be able to find the checkboxlist so that I can retreive the selected items and pass on the info to the appropriate textbox of the edititem of GridView?"
Jan 30 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Ahh now things become more clear: the button is within a GridView and you don't know how to handle the button click event. Sorry I missed the <EditItemTempla te> tag surrounding your code there.

Let me find you some resource that can help.
Jan 30 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Actually it turns out that it's quite easy.
All you have to do is supply a CommandArugment for the buttons:
Expand|Select|Wrap|Line Numbers
  1.  <asp:Button ID="Button2" runat="server" Text="OK" UseSubmitBehavior="True" CommandArgument="OkClick"/>
  2. <asp:Button ID="Button3" runat="server" Text="Cancel" UseSubmitBehavior="False"  CommandArgument="CancelClick" />
Then handle the RowCommand and check if the CommandArugment is "OkClick"
(Sorry if you're using C#, the following code is VB.NET...but you'll get the idea)
Expand|Select|Wrap|Line Numbers
  1. Private Sub myGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles myGridView.RowCommand
  2.  
  3.     If String.Compare(e.CommandArgument, "OkClick", True) = 0 Then
  4.  
  5.             Dim index As Integer = myGridView.EditIndex
  6.             Dim row As GridViewRow = myGridView.Rows(index)
  7.             Dim txt2 As TextBox = row.FindControl("TextBox2")
  8.  
  9.             Dim selectedItems As New StringBuilder
  10.  
  11.             Dim chkList As CheckBoxList = row.FindControl("CheckBoxList1")
  12.             For Each ckbox As ListItem In chkList.Items
  13.                 If ckbox.Selected Then
  14.                     selectedItems.Append(ckbox.Value)
  15.                     selectedItems.Append(", ")
  16.                 End If
  17.             Next
  18.  
  19.             txt2.Text = selectedItems.ToString
  20.         End If
  21. End Sub
:)

The following is a working code example.
In your aspx page:
Expand|Select|Wrap|Line Numbers
  1.  <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="false">
  2.     <Columns>
  3.        <asp:TemplateField HeaderText="ID">
  4.             <ItemTemplate>
  5.                 <asp:Label ID="PersonID" Text='<%#Eval("PersonID") %>' runat="server"></asp:Label>
  6.             </ItemTemplate>
  7.             <EditItemTemplate>
  8.                 <asp:TextBox ID="PersonIDUpdateValue" Text='<%#Eval("PersonID") %>' ></asp:TextBox>
  9.               </EditItemTemplate>
  10.         </asp:TemplateField> 
  11.         <asp:TemplateField HeaderText="Name">
  12.             <ItemTemplate>
  13.                 <asp:Label ID="PersonName" Text='<%#Eval("PersonName") %>' runat="server"></asp:Label>
  14.             </ItemTemplate>
  15.             <EditItemTemplate>
  16.                 <asp:TextBox ID="PersonNameUpdateValue" Text='<%#Eval("PersonName") %>' runat="server" ></asp:TextBox>
  17.             </EditItemTemplate>
  18.         </asp:TemplateField>
  19.         <asp:TemplateField HeaderText="Position">
  20.             <ItemTemplate>
  21.                 <asp:Label ID="PersonPostition" Text='<%#Eval("Position") %>' runat="server" ></asp:Label>
  22.             </ItemTemplate>
  23.             <EditItemTemplate>
  24.                 <asp:TextBox ID="PersonPostitionUpdateValue" Text='<%#Eval("PersonName") %>' runat="server" ></asp:TextBox>
  25.             </EditItemTemplate>
  26.         </asp:TemplateField>
  27.         <asp:TemplateField HeaderText="LanguagesKnown">
  28.             <ItemTemplate>
  29.                  <asp:Label ID="PersonPostition" Text='<%#Eval("LanguagesKnown") %>' runat="server" ></asp:Label>
  30.             </ItemTemplate>
  31.             <EditItemTemplate>
  32.                  <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("LanguagesKnown") %>'></asp:TextBox>
  33.                  <cc2:PopupControlExtender ID="PopupControlExtender2" runat="server"
  34.                  TargetControlID="TextBox2" PopupControlID="Panel1" Position="Bottom"
  35.                  CommitProperty="Value" CommitScript="e.Value">
  36.                  </cc2:PopupControlExtender>
  37.  
  38.                  <asp:Panel ID="Panel1" runat="server" style="background-color:White; border:solid 1px black;">
  39.                     <asp:CheckBoxList ID="CheckBoxList1" runat="server" 
  40.                         DataTextField="LanguagesList" 
  41.                         AutoPostBack="False">
  42.                         <asp:ListItem Text="English" Value="English"></asp:ListItem>
  43.                         <asp:ListItem Text="French" Value="French"></asp:ListItem>
  44.                         <asp:ListItem Text="Spanish" Value="Spanish"></asp:ListItem>
  45.                         <asp:ListItem Text="Mouse" Value="Mouse"></asp:ListItem>
  46.                         <asp:ListItem Text="Duck" Value="Duck"></asp:ListItem>
  47.                         <asp:ListItem Text="Dog" Value="Dog"></asp:ListItem>
  48.                      </asp:CheckBoxList>
  49.                      <asp:Button ID="Button2" runat="server" Text="OK" UseSubmitBehavior="True" CommandArgument="OkClick"/>
  50.                      <asp:Button ID="Button3" runat="server" Text="Cancel" UseSubmitBehavior="False"  CommandArgument="CancelClick" />
  51.                  </asp:Panel>
  52.             </EditItemTemplate>
  53.         </asp:TemplateField>
  54.         <asp:CommandField EditText="Edit" ButtonType="Link" ShowEditButton="true" />
  55.     </Columns>
  56.    </asp:GridView>
And in your VB code:
Expand|Select|Wrap|Line Numbers
  1.  Private _source As List(Of MySourceClass)
  2.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  3.  
  4.  
  5.         If IsPostBack = False Then
  6.             _source = New List(Of MySourceClass)
  7.             _source.Add(New MySourceClass(1, "Micky Mouse", "Engineer", "English, Mouse"))
  8.             _source.Add(New MySourceClass(2, "Mini Mouse", "House Wife", "English, Mouse"))
  9.             _source.Add(New MySourceClass(3, "Donald Duck", "Sailor", "English, Duck"))
  10.             ViewState("_source") = _source
  11.             myGridView.DataSource = _source
  12.             myGridView.DataBind()
  13.  
  14.         End If
  15.     End Sub
  16.     Private Sub myGridView_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles myGridView.RowCancelingEdit
  17.         _source = ViewState("_source")
  18.         myGridView.DataSource = _source
  19.         myGridView.EditIndex = -1
  20.         myGridView.DataBind()
  21.     End Sub
  22.  
  23.     Private Sub myGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles myGridView.RowCommand
  24.         If String.Compare(e.CommandArgument, "OkClick", True) = 0 Then
  25.  
  26.             Dim index As Integer = myGridView.EditIndex
  27.             Dim row As GridViewRow = myGridView.Rows(index)
  28.             Dim txt2 As TextBox = row.FindControl("TextBox2")
  29.  
  30.             Dim selectedItems As New StringBuilder
  31.  
  32.             Dim chkList As CheckBoxList = row.FindControl("CheckBoxList1")
  33.             For Each ckbox As ListItem In chkList.Items
  34.                 If ckbox.Selected Then
  35.                     selectedItems.Append(ckbox.Value)
  36.                     selectedItems.Append(", ")
  37.                 End If
  38.             Next
  39.  
  40.             txt2.Text = selectedItems.ToString
  41.         End If
  42.  
  43.  
  44.     End Sub
  45.  
  46.     Private Sub myGridView_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles myGridView.RowEditing
  47.         'myGridView.DataBind()
  48.         _source = ViewState("_source")
  49.         myGridView.DataSource = _source
  50.         myGridView.EditIndex = e.NewEditIndex
  51.         myGridView.DataBind()
  52.     End Sub
  53.  
  54.     Private Sub myGridView_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles myGridView.RowUpdated
  55.         _source = ViewState("_source")
  56.         myGridView.DataSource = _source
  57.         myGridView.EditIndex = -1
  58.         myGridView.DataBind()
  59.     End Sub
  60.  
  61.     Private Sub myGridView_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles myGridView.RowUpdating
  62.         Dim index As Integer = myGridView.EditIndex
  63.         Dim row As GridViewRow = myGridView.Rows(index)
  64.  
  65.     End Sub
  66.  
  67.  
  68.  <Serializable()> Protected Class MySourceClass
  69.         Private _id As Integer
  70.         Private _name As String
  71.         Private _position As String
  72.         Private _knownLanguages As String
  73.         Public Property PersonID() As Integer
  74.             Get
  75.                 Return _id
  76.             End Get
  77.             Set(ByVal value As Integer)
  78.                 _id = value
  79.             End Set
  80.         End Property
  81.         Public Property PersonName() As String
  82.             Get
  83.                 Return _name
  84.             End Get
  85.             Set(ByVal value As String)
  86.                 _name = value
  87.             End Set
  88.         End Property
  89.         Public Property Position() As String
  90.             Get
  91.                 Return _position
  92.             End Get
  93.             Set(ByVal value As String)
  94.                 _position = value
  95.             End Set
  96.         End Property
  97.         Public Property LanguagesKnown() As String
  98.             Get
  99.                 Return _knownLanguages
  100.             End Get
  101.             Set(ByVal value As String)
  102.                 _knownLanguages = value
  103.             End Set
  104.         End Property
  105.         Public Sub New(ByVal id As Integer, ByVal name As String, ByVal position As String, ByVal languages As String)
  106.             _id = id
  107.             _name = name
  108.             _position = position
  109.             _knownLanguages = languages
  110.         End Sub
  111.     End Class
  112.  
  113.  
-Frinny
Jan 30 '09 #5
deepakthegeek
5 New Member
Thank you very much Frinavale. The code that you had provided was very helpful.
Feb 2 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1502
by: wjer | last post by:
I am trying to do two things for a test app: 1) Populate a CheckboxList webcontrol by loading a list of subject names (for the DataTextField) and subject codes (for the DataValueField). 2) Respond to user selection by inserting their boolean values based on checked vs. unchecked boxes. I have a SQL Server table with a lot of columns of data type bit. All of the columns are named after different subject codes (such as HSmath, HSast, etc.)...
3
3778
by: Sully | last post by:
Hi, I am having a small problem generating an e-mail via an online form. I am creating an e-mail using the MailMessage command and I know that you have to do something special to render the values Checked with a CheckBoxList, but I don't know what to do or how to do it. If anyone could give me an example or send me to a link I would appreciate it. Thanks in advance.
1
12229
by: cyningeston | last post by:
OS: WinXP Pro, VB/ASP/ADO.NET I'm building a web-based supplier management application. For each supplier we are required by the FDA to track certain documents. I've managed to pull them from Access into a Gridview (Gridview1), in which I have AutoGenerateEditButton set to True. What I want is this: when a user clicks "Edit" on a line and it goes to edit mode, I want to grab the supplier's category (4th column of the grid, named...
1
15046
by: savajx1 | last post by:
I need to dynamically create a set of bound fields contained in a GridView control. I also have a single static CommandField that I can declare in the Columns <tagof the GridView control. I have to add controls dynamically as I am trying to write a reusable , general , spreadsheet like display control that can take advantage of the built- in update and delete features of the SqlDataSource/Gridview controls. This user control can get its...
7
6836
by: nussu | last post by:
Hi, Plz provide me javascript : javascript for a textbox to accept the values in decimals and within range i need to enter a value in textbox like 1.03 and it should be <3 (lessthan 3). Plz help me. Rgds,
1
3354
by: Ajumal | last post by:
i want to fill my gridview from textbox.no database should be used. The process must done in a button click
0
2513
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. In this table there are multiple columns that cannot be NULL, which, are bound to other controls (but they're not really important at this time). I create a new row via the currency manager like so: _currencyManager.AddNew() _currentRow =...
0
4282
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't want to have my parameter names in those methods have to be "original_Parametername" or even if I change the OldValuesParameterFormatString to get rid of the "original" I would still have just "Parametername". I think most people user parameters...
0
9633
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10137
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8959
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7483
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.