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 -
<EditItemTemplate>
-
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("LanguagesKnown") %>'></asp:TextBox>
-
-
<cc1:PopupControlExtender ID="PopupControlExtender2" runat="server"
-
TargetControlID="TextBox2" PopupControlID="Panel1" Position="Bottom"
-
CommitProperty="Value" CommitScript="e.Value">
-
</cc1:PopupControlExtender>
-
-
<asp:Panel ID="Panel1" runat="server" CssClass="popupControl" >
-
-
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="AccessDataSource2" AppendDataBoundItems="True" DataTextField="LanguagesList"
-
-
AutoPostBack="False">
-
</asp:CheckBoxList>
-
<asp:Button ID="Button2" runat="server" Text="OK" UseSubmitBehavior="True" />
-
<asp:Button ID="Button3" runat="server" Text="Cancel" UseSubmitBehavior="False" />
-
</asp:Panel>
-
-
</EditItemTemplate>
-
I would appreciate if someone get help me out in achieving my objective.
Deepak Jadhav
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....
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?"
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.
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: -
<asp:Button ID="Button2" runat="server" Text="OK" UseSubmitBehavior="True" CommandArgument="OkClick"/>
-
<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) -
Private Sub myGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles myGridView.RowCommand
-
-
If String.Compare(e.CommandArgument, "OkClick", True) = 0 Then
-
-
Dim index As Integer = myGridView.EditIndex
-
Dim row As GridViewRow = myGridView.Rows(index)
-
Dim txt2 As TextBox = row.FindControl("TextBox2")
-
-
Dim selectedItems As New StringBuilder
-
-
Dim chkList As CheckBoxList = row.FindControl("CheckBoxList1")
-
For Each ckbox As ListItem In chkList.Items
-
If ckbox.Selected Then
-
selectedItems.Append(ckbox.Value)
-
selectedItems.Append(", ")
-
End If
-
Next
-
-
txt2.Text = selectedItems.ToString
-
End If
-
End Sub
:)
The following is a working code example.
In your aspx page: -
<asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="false">
-
<Columns>
-
<asp:TemplateField HeaderText="ID">
-
<ItemTemplate>
-
<asp:Label ID="PersonID" Text='<%#Eval("PersonID") %>' runat="server"></asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox ID="PersonIDUpdateValue" Text='<%#Eval("PersonID") %>' ></asp:TextBox>
-
</EditItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="Name">
-
<ItemTemplate>
-
<asp:Label ID="PersonName" Text='<%#Eval("PersonName") %>' runat="server"></asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox ID="PersonNameUpdateValue" Text='<%#Eval("PersonName") %>' runat="server" ></asp:TextBox>
-
</EditItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="Position">
-
<ItemTemplate>
-
<asp:Label ID="PersonPostition" Text='<%#Eval("Position") %>' runat="server" ></asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox ID="PersonPostitionUpdateValue" Text='<%#Eval("PersonName") %>' runat="server" ></asp:TextBox>
-
</EditItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="LanguagesKnown">
-
<ItemTemplate>
-
<asp:Label ID="PersonPostition" Text='<%#Eval("LanguagesKnown") %>' runat="server" ></asp:Label>
-
</ItemTemplate>
-
<EditItemTemplate>
-
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("LanguagesKnown") %>'></asp:TextBox>
-
<cc2:PopupControlExtender ID="PopupControlExtender2" runat="server"
-
TargetControlID="TextBox2" PopupControlID="Panel1" Position="Bottom"
-
CommitProperty="Value" CommitScript="e.Value">
-
</cc2:PopupControlExtender>
-
-
<asp:Panel ID="Panel1" runat="server" style="background-color:White; border:solid 1px black;">
-
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
-
DataTextField="LanguagesList"
-
AutoPostBack="False">
-
<asp:ListItem Text="English" Value="English"></asp:ListItem>
-
<asp:ListItem Text="French" Value="French"></asp:ListItem>
-
<asp:ListItem Text="Spanish" Value="Spanish"></asp:ListItem>
-
<asp:ListItem Text="Mouse" Value="Mouse"></asp:ListItem>
-
<asp:ListItem Text="Duck" Value="Duck"></asp:ListItem>
-
<asp:ListItem Text="Dog" Value="Dog"></asp:ListItem>
-
</asp:CheckBoxList>
-
<asp:Button ID="Button2" runat="server" Text="OK" UseSubmitBehavior="True" CommandArgument="OkClick"/>
-
<asp:Button ID="Button3" runat="server" Text="Cancel" UseSubmitBehavior="False" CommandArgument="CancelClick" />
-
</asp:Panel>
-
</EditItemTemplate>
-
</asp:TemplateField>
-
<asp:CommandField EditText="Edit" ButtonType="Link" ShowEditButton="true" />
-
</Columns>
-
</asp:GridView>
And in your VB code: -
Private _source As List(Of MySourceClass)
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
-
-
If IsPostBack = False Then
-
_source = New List(Of MySourceClass)
-
_source.Add(New MySourceClass(1, "Micky Mouse", "Engineer", "English, Mouse"))
-
_source.Add(New MySourceClass(2, "Mini Mouse", "House Wife", "English, Mouse"))
-
_source.Add(New MySourceClass(3, "Donald Duck", "Sailor", "English, Duck"))
-
ViewState("_source") = _source
-
myGridView.DataSource = _source
-
myGridView.DataBind()
-
-
End If
-
End Sub
-
Private Sub myGridView_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles myGridView.RowCancelingEdit
-
_source = ViewState("_source")
-
myGridView.DataSource = _source
-
myGridView.EditIndex = -1
-
myGridView.DataBind()
-
End Sub
-
-
Private Sub myGridView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles myGridView.RowCommand
-
If String.Compare(e.CommandArgument, "OkClick", True) = 0 Then
-
-
Dim index As Integer = myGridView.EditIndex
-
Dim row As GridViewRow = myGridView.Rows(index)
-
Dim txt2 As TextBox = row.FindControl("TextBox2")
-
-
Dim selectedItems As New StringBuilder
-
-
Dim chkList As CheckBoxList = row.FindControl("CheckBoxList1")
-
For Each ckbox As ListItem In chkList.Items
-
If ckbox.Selected Then
-
selectedItems.Append(ckbox.Value)
-
selectedItems.Append(", ")
-
End If
-
Next
-
-
txt2.Text = selectedItems.ToString
-
End If
-
-
-
End Sub
-
-
Private Sub myGridView_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles myGridView.RowEditing
-
'myGridView.DataBind()
-
_source = ViewState("_source")
-
myGridView.DataSource = _source
-
myGridView.EditIndex = e.NewEditIndex
-
myGridView.DataBind()
-
End Sub
-
-
Private Sub myGridView_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles myGridView.RowUpdated
-
_source = ViewState("_source")
-
myGridView.DataSource = _source
-
myGridView.EditIndex = -1
-
myGridView.DataBind()
-
End Sub
-
-
Private Sub myGridView_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles myGridView.RowUpdating
-
Dim index As Integer = myGridView.EditIndex
-
Dim row As GridViewRow = myGridView.Rows(index)
-
-
End Sub
-
-
-
<Serializable()> Protected Class MySourceClass
-
Private _id As Integer
-
Private _name As String
-
Private _position As String
-
Private _knownLanguages As String
-
Public Property PersonID() As Integer
-
Get
-
Return _id
-
End Get
-
Set(ByVal value As Integer)
-
_id = value
-
End Set
-
End Property
-
Public Property PersonName() As String
-
Get
-
Return _name
-
End Get
-
Set(ByVal value As String)
-
_name = value
-
End Set
-
End Property
-
Public Property Position() As String
-
Get
-
Return _position
-
End Get
-
Set(ByVal value As String)
-
_position = value
-
End Set
-
End Property
-
Public Property LanguagesKnown() As String
-
Get
-
Return _knownLanguages
-
End Get
-
Set(ByVal value As String)
-
_knownLanguages = value
-
End Set
-
End Property
-
Public Sub New(ByVal id As Integer, ByVal name As String, ByVal position As String, ByVal languages As String)
-
_id = id
-
_name = name
-
_position = position
-
_knownLanguages = languages
-
End Sub
-
End Class
-
-
-Frinny
Thank you very much Frinavale. The code that you had provided was very helpful.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.)...
|
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.
|
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...
|
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...
|
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,
| |
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
|
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 =...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |