Welcome Guest Search | Active Topics | Sign In | Register

dropdownlist in grid Options
Ria
Posted: Friday, January 25, 2008 8:33:02 AM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
I'm searching for an example of populating a dropdownlist in eo.grid from the database.
can somebody help me?
eo_support
Posted: Friday, January 25, 2008 9:46:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Hi,

You would use a CustomColumn with it's EditorTemplate set:

http://www.essentialobjects.com/ViewDoc.aspx?t=Grid%2fcustom_column.html

You can populate the drop down list items from the DataBase, but you will not be able to do have different list items for different grid items. Also you will need to write some code to load and save value to and from the grid. That part would be unrelated to populating the dropdownlist at all.

Thanks
Ria
Posted: Saturday, January 26, 2008 12:45:24 AM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
in asp2.0 I have routines for that purpose.
with the template fields all kinds of dropdownlists are possible
are you going to make such things in your grid to?

dd = CType(Grid1.FindControl("groepen"), DropDownList)
func.LoadDataToLookUp(dd, "select id, groep from nslBekwaamheidsGroepen", "", True)
eo_support
Posted: Saturday, January 26, 2008 7:20:58 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Hi Ria,

You won't be able to use FindControl with the current version. We will look into it and see what we can do.

Thanks
Ria
Posted: Sunday, January 27, 2008 2:04:03 AM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
Hi,

I implemented the grid with simple data and two dropdownlists that will have the same values at all our custumers and it works and shows very good.
I should like to implement it in all my pages but then I need:
1 the dropdownlists populating with data from the database
2 the possibilty of hiding columns (depending on the application rights of the user I hide the insert, update and other buttons)
the last one is not necessary but nice
3 It would be nice if the width of the columns could be set to auto
I hope you and your team can realise that.
eo_support
Posted: Sunday, January 27, 2008 5:04:51 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Thanks for the suggestions! We would definitely keep them in mind when we develop our next version.
Ria
Posted: Sunday, January 27, 2008 5:15:31 AM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
as all our customers ask by that answer any idea whenWhistle
eo_support
Posted: Sunday, January 27, 2008 5:35:24 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Hi,

1. FindControl support can be made available soon, which should satisfy #1;
2. #2/#3 can be implemented in your code (with some support from the Grid) or on the Grid. We will need to evaluate the advantage and disadvantage before deciding on how much support is to be implemented on the Grid and how much should be left to user code, or to implement any support on the Grid at all;

Thanks
eo_support
Posted: Thursday, January 31, 2008 9:21:45 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Hi,

We've posted a new build that supports FindControl. You would need to call FindControl on CustomColumn.EditorInstance. For example:

EO.Web.CustomColumn column = (EO.Web.CustomColumn)grid1.Columns[3];
column.EditorTemplate.FindControl("DropDownList1");

Thanks
Ria
Posted: Thursday, January 31, 2008 11:03:18 PM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
I assume this is javascript in the function on begin_edit
where and how do I define dropdownlist1 ?
in design mode when I ask the properties of grid1 I get the message object ref not set to an instance of an object
eo_support
Posted: Friday, February 1, 2008 5:06:13 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Ria wrote:
I assume this is javascript in the function on begin_edit
where and how do I define dropdownlist1 ?
in design mode when I ask the properties of grid1 I get the message object ref not set to an instance of an object


Hi Ria,

I am not exactly sure what you mean. In order to use a CustomItem, you go to HTML view to type in its EditorTemplate. The code in previous post is server side code. FindControl has nothing to do with JavaScript. The sample project demonstrated how to use JavaScript to initializes the drop down list in begin_edit, but that has nothing to do with the data binding question that you are asking.

Also, the code only works on the new build that we posted (see your private message for download location). It won't work on your previous build.

Thanks
Ria
Posted: Saturday, February 2, 2008 10:00:39 AM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
hi,

hope you can help me.
it works nice but the selected value doesn't reach my updatequery
what do I do wrong?

my aspx

<%@ Page Language="VB" MasterPageFile="~/FS2.master" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="pages_Test" title="Bigregistratie" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="EO" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
function on_end_edit(cell)
{
//Get the new value from the drop down box
// var dropDownBox = document.getElementById("DdGroep");
// var v = dropDownBox.selectedValue;
//
//
// //Return the new value to the grid
// return v;
}

</script>
<%--<EO:CallbackPanel ID="CallbackPanel1" runat="server" Height="145px" Triggers="{ControlID:Grid1;Parameter:},{ControlID:LButtonBevestig;Parameter:}"
Width="678px"> --%>
<eo:Grid ID="Grid1" runat="server" BorderColor="#C7D1DF" BorderWidth="1px" ColumnHeaderAscImage="00050303"
ColumnHeaderDescImage="00050304" ColumnHeaderDividerImage="00050302" FixedColumnCount="1" KeyField="Id"
Font-Bold="False" Font-Italic="False" Font-Names="Verdana" Font-Overline="False"
Font-Size="9pt" Font-Strikeout="False" Font-Underline="False" GridLineColor="199, 209, 223"
GridLines="Both" Height="200px" ItemHeight="19" Width="578px"><ItemStyles>
<EO:GridItemStyleSet>
<ItemStyle CssText="background-color: white" />
<CellStyle CssText="padding-left:8px;padding-top:2px; color:#336699;" />
<SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
<ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
</EO:GridItemStyleSet>
</ItemStyles>
<ColumnTemplates>
<EO:TextBoxColumn>
<TextBoxStyle CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 8.75pt; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; FONT-FAMILY: Tahoma" />
</EO:TextBoxColumn>
<EO:DateTimeColumn>
<DatePicker ControlSkinID="None" DayCellHeight="16" DayCellWidth="19" DayHeaderFormat="FirstLetter"
DisabledDates="" OtherMonthDayVisible="True" SelectedDates="" TitleLeftArrowImageUrl="DefaultSubMenuIconRTL"
TitleRightArrowImageUrl="DefaultSubMenuIcon">
<TodayStyle CssText="font-family: tahoma; font-size: 12px; border-right: #bb5503 1px solid; border-top: #bb5503 1px solid; border-left: #bb5503 1px solid; border-bottom: #bb5503 1px solid" />
<PickerStyle CssText="border-bottom-color:#7f9db9;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#7f9db9;border-left-style:solid;border-left-width:1px;border-right-color:#7f9db9;border-right-style:solid;border-right-width:1px;border-top-color:#7f9db9;border-top-style:solid;border-top-width:1px;font-family:Courier New;font-size:8pt;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:1px;padding-left:2px;padding-right:2px;padding-top:2px;" />
<SelectedDayStyle CssText="font-family: tahoma; font-size: 12px; background-color: #fbe694; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
<DisabledDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
<CalendarStyle CssText="background-color: white; border-right: #7f9db9 1px solid; padding-right: 4px; border-top: #7f9db9 1px solid; padding-left: 4px; font-size: 9px; padding-bottom: 4px; border-left: #7f9db9 1px solid; padding-top: 4px; border-bottom: #7f9db9 1px solid; font-family: tahoma" />
<TitleArrowStyle CssText="cursor:hand" />
<DayHoverStyle CssText="font-family: tahoma; font-size: 12px; border-right: #fbe694 1px solid; border-top: #fbe694 1px solid; border-left: #fbe694 1px solid; border-bottom: #fbe694 1px solid" />
<MonthStyle CssText="font-family: tahoma; font-size: 12px; margin-left: 14px; cursor: hand; margin-right: 14px" />
<TitleStyle CssText="background-color:#9ebef5;font-family:Tahoma;font-size:12px;padding-bottom:2px;padding-left:6px;padding-right:6px;padding-top:2px;" />
<OtherMonthDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
<DayHeaderStyle CssText="font-family: tahoma; font-size: 12px; border-bottom: #aca899 1px solid" />
<DayStyle CssText="font-family: tahoma; font-size: 12px; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
</DatePicker>
</EO:DateTimeColumn>
<EO:MaskedEditColumn>
<MaskedEdit ControlSkinID="None" TextBoxStyle-CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; font-family:Courier New;font-size:8pt;">
</MaskedEdit>
</EO:MaskedEditColumn>
</ColumnTemplates>

<FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;"></FooterStyle>
<Columns>
<EO:EditCommandColumn CancelText="&lt;img Title = 'Opslaan' src='../Images/button.undo.gif' border='0' /&gt;"
EditText="&lt;img title='Wijzig' src='../Images/icon_edit.GIF' border='0' /&gt;"
Name="Wijzig" UpdateText="&lt;img Title = 'Opslaan' src='../Images/icon_groen.GIF' border='0' /&gt;"
Width="20">
</EO:EditCommandColumn>
<EO:DeleteCommandColumn DeleteText="&lt;img Title = 'Verwijder deze regel' src='../Images/icon_delete.GIF' border='0' /&gt;"
Name="Verwijder" Width="20">
</EO:DeleteCommandColumn>
<EO:StaticColumn AllowSort="True" DataField="Persoon" HeaderText="Persoon" SortOrder="Ascending"
Text="">
</EO:StaticColumn>
<EO:StaticColumn DataField="Naam" HeaderText="Naam" Text="" Width="150">
</EO:StaticColumn>
<EO:CustomColumn DataField="Handeling" HeaderText="Groep" Name="Groep" ClientSideEndEdit = "on_end_edit">
<EditorTemplate>
<asp:DropDownList ID = "DdGroep" runat ="server" DataSourceID = "SqlGroep" DataTextField="handeling" DataValueField="code_beroepsgroep"></asp:DropDownList><asp:SqlDataSource ID="SqlGroep" runat="server" ConnectionString="<%$ ConnectionStrings:FriendsysConnectionString %>"
SelectCommand="SELECT code_beroepsgroep, handeling FROM nslBekwaamheidsHandelingen"></asp:SqlDataSource>
</EditorTemplate>
</EO:CustomColumn>
<EO:TextBoxColumn DataField="Bigregnr" HeaderText="Nummer" Width="125">
</EO:TextBoxColumn>
<EO:CustomColumn DataField="Register" Name="Register">
</EO:CustomColumn>
</Columns>

<ColumnHeaderStyle CssText="background-image:url('00050301');padding-left:8px;padding-top:2px;font-weight: bold;color:white;"></ColumnHeaderStyle>
</eo:Grid>
<asp:Panel id="panChanges" Width="800px" runat="server" Visible="False">Samenvatting:</asp:Panel>
<asp:Label ID="LbHelp" runat="server"
Text="Klik op OPSLAAN om uw wijzigingen definitief te maken"></asp:Label>
<asp:LinkButton ID="LButtonBevestig" runat="server" Text="&lt;img Title = 'Opslaan' src='../Images/Save.GIF' border='0' /&gt;" Height="46px" Width="46px" />
<%-- </EO:CallbackPanel> --%>

</asp:Content>

the vb code

Imports System
Imports EO.Web
Imports EO.Web.CustomColumn

Partial Class pages_test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then

binddata()
End If
End Sub
Protected Sub binddata()

Dim conString As String = System.Configuration.ConfigurationManager.AppSettings("Conn_string")
'Dim autortabel As String = "tblAutor" & userlogin.Groupnaam
Dim aanvsql As String = ""
Dim sql As String = ""
Dim conn As Data.SqlClient.SqlConnection
Dim cmd As Data.SqlClient.SqlCommand
Dim reader As Data.SqlClient.SqlDataReader
Dim dd As DropDownList
Dim uitbrsql As String = ""
'If Session("Aidie") = Nothing Then Session("Aidie") = ""
'If Session("Aidie").ToString <> "" Then
' TbKop.Text = Session("Aidie") & " " & Session("Aidienaam")
'End If
'If DdRegister.SelectedValue = "" Then
'Else
' uitbrsql = uitbrsql & " and ( coalesce(register,1) =" & DdRegister.SelectedValue & " ) "
'End If
'If DdHandeling.SelectedValue = "" Then
'Else
' uitbrsql = uitbrsql & " and (coalesce(handeling,'') = " & DdHandeling.SelectedValue & " ) "
'End If
'If Session("Aidie") = "" Then
'Else
' uitbrsql = uitbrsql & " and (persoon = " & Session("Aidie") & " ) "
'End If
sql = "SELECT tblBigregistratie.Persoon, tblBigregistratie.Bigregnr, tblBigregistratie.Handeling, tblBigregistratie.[Begin], tblBigregistratie.Eind, tblBigregistratie.Bft, tblBigregistratie.Bev_beperkingen, tblBigregistratie.Bev_beperkingen_oms, tblBigregistratie.Specialisme_id, tblBigregistratie.Spec_1, tblBigregistratie.Spec_2, tblBigregistratie.Spec_3, tblBigregistratie.Spec_4, tblBigregistratie.Register,tblPersoneel.NAAM_VOORLETTERS as naam, tblBigregistratie.id FROM tblBigregistratie INNER JOIN tblPersoneel ON tblBigregistratie.Persoon = tblPersoneel.id where 2 = 2 " & uitbrsql
conn = New Data.SqlClient.SqlConnection(conString)
cmd = New Data.SqlClient.SqlCommand(sql, conn)
conn.Open()
Try
cmd = New Data.SqlClient.SqlCommand(sql, conn)
reader = cmd.ExecuteReader()
If reader.HasRows() Then
Grid1.DataSource = reader
Grid1.DataBind()

Else

'LblMessage.Text = "Wijzig de selectie "
End If
reader.Close()
Catch ex As Exception
'LblMessage.Text += "Fout beschrijving" + ": " + ex.Message() + "<p>"
Finally
cmd.Dispose()
conn.Close()
End Try
'dd = CType(Grid1.FindControl("groepen"), DropDownList)


End Sub
Protected Sub LButtonBevestig_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LButtonBevestig.Click
panChanges.Visible = True
Dim [text] As String = ""
Dim controle As String = ""
Dim s As String = String.Empty
Dim d As DropDownList
If Grid1.ChangedItems.Length = 0 Then
s += "Geen records gewijzigd."
Else
Dim item As GridItem
s += "<br>"
For Each item In Grid1.ChangedItems
' EO.Web.CustomColumn column = (EO.Web.CustomColumn)grid1.Columns[3];
'grid1.column.EditorTemplate.FindControl("DropDownList1");
d = CType(Grid1.FindControl("DdGroep"), DropDownList)

[text] = String.Format("Gewijzigd: Record = {0}, Registratienummer -> {1}, Persoon -> {2}", item.Key, item.Cells("Bigregnr").Value, item.Cells("Naam").Value)
func.voersqluit("update tblbigregistratie set bigregnr ='" & item.Cells("Bigregnr").Value & "' ,register = " & item.Cells("Register").Value & ",handeling = '" & item.Cells("Handeling").Value & "' where id =" & item.Key)
s += "<br />"
s += [text]
Next item
End If
If Grid1.DeletedItems.Length = 0 Then
s += "<br>"
s += "Geen records verwijderd."
Else
Dim item As GridItem
s += "<br>"
For Each item In Grid1.ChangedItems
[text] = String.Format("Gewijzigd: Record = {0}, Registratienummer -> {1}, Persoon -> {2}", item.Key, item.Cells("Bigregnr").Value, item.Cells("Naam").Value)
'Dim [text] As String = String.Format("Item Changed: Key = {0}, Posted At -> {1}, Posted By -> {2}, Topic -> {3}", item.Key, item.Cells("Bigregnr").Value, item.Cells("PostedBy").Value, item.Cells("Topic").Value)
func.voersqluit("delete from tblbigregistratie where id =" & item.Key)
s += "<br />"
s += [text]
Next item
End If

If Grid1.AddedItems.Length = 0 Then
s += "<br>"
s += "Geen records toegevoegd."
Else
Dim item As GridItem
s += "<br>"
For Each item In Grid1.AddedItems
'Dim [text] As String = String.Format("Item Changed: Key = {0}, Posted At -> {1}, Posted By -> {2}, Topic -> {3}", item.Key, item.Cells("Bigregnr").Value, item.Cells("PostedBy").Value, item.Cells("Topic").Value)
If Session("Aidie") = "" Then
[text] = "Kies eerst een persoon "
Else
If item.Cells("Bigregnr").Value = "" Then
[text] = "Het registratienummer is niet ingevuld "
Else
controle = func.LoadDataToTextbox("Select persoon from tblbigregistratie where bigregnr = " & item.Cells("Bigregnr").Value, "")
If controle = "" Then
func.voersqluit("INSERT INTO tblBigregistratie ([Persoon] ,[Bigregnr] ,[Handeling] ,[Register]) VALUES (" & Session("Aidie") & " ,'" & item.Cells("Bigregnr").Value & "' ,'" & item.Cells("Handeling").Value & "' ," & item.Cells("Register").Value & ")")
[text] = String.Format("Toegevoegd: Record = {0}, Registratienummer -> {1}, Persoon -> {2}", item.Key, item.Cells("Bigregnr").Value, item.Cells("Naam").Value)
Else
[text] = "Het registratienummer komt reeds voor bij persoon " & controle
End If
End If
End If

s += "<br />"
s += [text]

Next item
End If
Dim info As New Literal()
info.Text = s
panChanges.Controls.Add(info)
End Sub

End Class


eo_support
Posted: Saturday, February 2, 2008 11:18:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Hi Ria,

It never does and never will. The purpose of EditorTemplate is for you to customize the editor for your Grid. The value is never transfered back to the server via EditorTemplate. The reason is very simple, the same editor template is used to edit all cells in the column. So there are multiple values and only one template involved, in another word, there is no one to one relation between editor and cell value. So you can not get the value from the editor. In order to set/get values, you must follow steps outlined here:

http://www.essentialobjects.com/ViewDoc.aspx?t=Grid%2fcustom_column.html

You should also go over other topics for the Grid. Our Grid is very powerful but it's different than standard ASP.NET Grid, which offers no client side functionalities (so you can expect to do everything on the server side). Our grid implements a lot of functionalities on the client side, you won't need to deal with them when you use all other columns, but you must deal with client side JavaScript when you use CustomColumn.

Thanks
Ria
Posted: Tuesday, February 5, 2008 12:24:35 PM
Rank: Advanced Member
Groups: Member

Joined: 6/6/2007
Posts: 37
Hi,

Thank you very much for your patience.
last night I woke up, saw your mail and found the solution.
afterwards very simple.
for all other asp ers this is the code

function on_begin_edit(cell)
{
//Get the current cell value
var v = cell.getValue();

//Use index 0 if there is no value
if (v == null)
v = 0;

//Load the value into our drop down box
var dropDownBox = document.getElementById("ctl00_ContentPlaceHolder1_Grid1_edit_DdGroep");
dropDownBox.value = v;
}
function on_end_edit(cell)
{
//Get the new value from the drop down box
var dropDownBox = document.getElementById("ctl00_ContentPlaceHolder1_Grid1_edit_DdGroep");
var v = dropDownBox.value;


//Return the new value to the grid
return v;
}

thanks again, up to the splitter
eo_support
Posted: Tuesday, February 5, 2008 1:03:20 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,094
Great! I am glad you found out and thanks for sharing! The key is to use the control's ClientID, not ID, on the client side. This is the golden rule when work with client side JavaScript.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.