473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Updating GridView EditItem textbox with popupextender panel checkboxlist values

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 popupcontrolextender 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 7717
Frinavale
9,735 Expert Mod 8TB
In the "Ok Button" Click Event, display the selected items of the CheckBoxList separated by commas, in the TextBox....
Jan 30 '09 #2
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 Expert Mod 8TB
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 <EditItemTemplate> tag surrounding your code there.

Let me find you some resource that can help.
Jan 30 '09 #4
Frinavale
9,735 Expert Mod 8TB
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
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
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)...
3
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...
1
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...
1
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...
7
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...
1
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
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. ...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.