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 -
<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 7717
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?"
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.
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)...
|
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...
|
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...
|
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...
|
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...
|
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. ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |