|
|
Subject:
Need to add a drop down list to a datagrid
Category: Computers > Programming Asked by: sunmoon-ga List Price: $100.00 |
Posted:
05 Jan 2005 16:15 PST
Expires: 04 Feb 2005 16:15 PST Question ID: 452649 |
I have set up a webpage that lists equipment and allows users to select a single item and reserve one or more of the item. You can see this page at: http://www.pilatesontour.com/equipment/EquipReserve.aspx Click on 'Get Equipment List' at the bottom of the page. What I would like to be able to do is to render either a drop down list (prefered) or a text box on each row, that allows users to select the quantity desired for one or more pieces of equipment (versus only being able to select one piece of equipment/order). The drop down list should be populated with 1 through n, where n = quantity available. The table is read from an Access DB using asp.net and VB. I've been able to add the control to the datagrid, but I can not figure out how to read through the list (for each drop down list...). I would like to get a page with working code that would allow me to grab the quantities for each equipment. I will need to somehow know which quantity went with which equipment. |
|
There is no answer at this time. |
|
Subject:
Re: Need to add a drop down list to a datagrid
From: crythias-ga on 05 Jan 2005 21:49 PST |
I'm not too familiar with VB, but here's a hint: SELECT ProductId, Name, count(inventory.QTY) AS quantity from PRODUCT, Inventory where Product.ProductID=Inventory.ProductID (or some such). Run the query. Get the result in an array. while ($info=fetch_object($result_array)) { print "<colorful><tags><anchors>" . $info->Name . "</close></tags>"; print "<Select name=\"chooseqty[". $info->ProductId . "]>"; // create an array. for ($I=1 to $info->quantity) { print "<option "; if ($I==1) { print "selected=True"; } print ">" . $I . "</option>\n"; } print "</select>"; } This code probably won't work for any real language, although it's very very loosely based upon PHP. The short info is that you just run a for/next loop from 1 to quantity and create <option> tags around the quantity count index, and <select> tags around the loop. I'm sure someone has a better idea... Although, forcing choices from stock qty of inventory means no back-orders are possible. Hope it helps somewhat. |
Subject:
Re: Need to add a drop down list to a datagrid
From: crythias-ga on 05 Jan 2005 21:50 PST |
PS: I'm not a GA Researcher. Above was a free comment. |
Subject:
Re: Need to add a drop down list to a datagrid
From: hmm-ga on 06 Jan 2005 12:44 PST |
http://p2p.wrox.com/topic.asp?TOPIC_ID=5756 The above link might help you sunmoon. Also use keywords such as "access drop down to datagrid asp.net" in google and groups.google.com There are good number of people discussing with working solutions in groups.google.com, please use the below link. http://groups-beta.google.com/groups?q=access%20drop%20down%20to%20datagrid%20asp.net&hl=en&lr=&sa=N&tab=wg |
Subject:
Re: Need to add a drop down list to a datagrid
From: akash_kava-ga on 30 Jan 2005 02:43 PST |
DataGrid has one event, called ItemCreated. You can override this event and modify anything related to your Row. You have to add panel (control holder) in any of your datagrid template column. Say for example it is cPanel This can work.. DataGrid_ItemCreated(sender as Object, e as EventArgs) { i = e.Item.DataSetIndex ' This will return index of item you can now use i to determine what control you want to display for this row e.Item.FindControl("cPanel").Controls.Add( Add appropriate control here ) } |
Subject:
Re: Need to add a drop down list to a datagrid
From: prathap_m-ga on 31 Jan 2005 03:33 PST |
I think this should work First in the column,call a function that builds and displays the list with data <td> <SELECT name ="xxx"> populate(arg1,arg2,...) </SELECT> </td> <% populate(param1,param2) { sql="SELECT *from table name where <<condition>>" //YOUR QUERY //CREATE CONNECTION TO DATABASE set conn=Server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.Jet.OLEDB.4.0" conn.Open(Server.Mappath("DATABASE NAME")) set rs = Server.CreateObject("ADODB.recordset") //Run QUERY AND BUILD RECORD SET rs.Open sql, conn do until rs.EOF for each x in rs.Fields %> <OPTION><% x %></OPTION> //Display it in dropdown list <% next Response.Write("<br />") rs.MoveNext loop end procedure %> Now You call this part in each column. I am not expert in scripting,i knew VB well. so just try it out Prathap M |
Subject:
Re: Need to add a drop down list to a datagrid
From: awilinsk-ga on 22 Sep 2005 05:14 PDT |
I am doing about the same thing, only my dropdownlist is filled with the same values from a database, but the theory still works. DataGrid Code: <asp:datagrid id="datListProgs" autogeneratecolumns="false" datakeyfield="id" oncancelcommand="Cancel_Prog_Grid" ondeletecommand="Delete_Prog_Grid" oneditcommand="Edit_Prog_Grid" onitemcommand="Command_Prog_Grid" onitemdatabound="ItemBound_Prog_Grid" onupdatecommand="Update_Prog_Grid" runat="server" showfooter="true" style="width:306px;"> <columns> <asp:templatecolumn headertext="Program Type"> <itemtemplate> <%# DataBinder.Eval(Container.DataItem,"description") %> </itemtemplate> <edititemtemplate> <asp:dropdownlist id="lstEditProgType" cssclass="textbox" datatextfield="description" datavaluefield="prog_type" runat="server" /> </edititemtemplate> </asp:templatecolumn> </columns> </asp:datagrid> Item Data Bound Event Code: Public Sub ItemBound_Prog_Grid(sender As Object, e As DataGridItemEventArgs) Select Case e.Item.ItemType Case ListItemType.EditItem Call Load_ProgType_Listbox(CType(e.Item.Cells(2).FindControl("lstEditProgType"),DropDownList)) CType(e.Item.Cells(2).FindControl("lstEditProgType"),DropDownList).SelectedValue=e.Item.Cells(5).Text End Select End Sub Load ListBox Code: Public Sub Load_ProgType_Listbox(ByRef lst As DropDownList) Dim strSql As String Dim sqlCnn As SqlConnection Dim sqlCmd As SqlCommand Try strSql="select..." sqlCnn=New SqlConnection(ConfigurationSettings.AppSettings("connectString")) sqlCnn.Open() sqlCmd=New SqlCommand(strSql,sqlCnn) lst.DataSource=sqlCmd.ExecuteReader(CommandBehavior.CloseConnection) lst.DataBind() Catch err As Exception Throw(err) Finally If Not sqlCnn.State = ConnectionState.Closed Then sqlCnn.Close() End If End Try End Sub The code works by calling a procedure to load the dropdownlist. The procedure is taking in a dropdownlist by a parameter. the "ByRef" is very important, because you want to pass the actual dropdownlist object and not just a copy of it. On each item created the ItemDataBound event checks to see if it is of type EditItem (you can change that to anything: Item, AlternatingItem, Header, etc). If the item is of type EditItem, then the Load ListBox procedure is called, loading the listbox with the actual values from the database. Then the selected value of the dropdownlist is is set by one of the cells in the databrid. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |