Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Go Back  Xtreme Visual Basic Talk > > > Retrun Selection in DropDown Box to DataGrid


Reply
 
Thread Tools Display Modes
  #21  
Old 12-08-2006, 09:59 AM
wayneph's Avatar
waynephRetrun Selection in DropDown Box to DataGrid wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default


yes. in the ItemDataBound event, you can check for the EditItemType, and then set you're value in that part of the If Statement. Just DirectCast your control to TextBox instead of Label this time.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #22  
Old 12-08-2006, 12:34 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

THanks!!!

Quote:
Originally Posted by mountainbikinglife
I appreciate all the help!
Last thing for the week... if I wanted to modify the format of the textbox's that are automatically created as a part of the

OnEditCommand = "dgPaging_Edit" function, how would I go about doing that? I have figured out how to modify the format of the textbox generated in the Template Column, I have used the following coding to achieve that....

DirectCast(e.Item.FindControl("textbox1"), TextBox).ForeColor = Drawing.Color.Blue

I just cannot figure out how to change the formatting in the autogenerated textboxes... espcially because the textbox is not dimensoned until the dgPaging_Update Function.

Quote:
Originally Posted by wayneph
yes. in the ItemDataBound event, you can check for the EditItemType, and then set you're value in that part of the If Statement. Just DirectCast your control to TextBox instead of Label this time.
Reply With Quote
  #23  
Old 12-08-2006, 01:13 PM
wayneph's Avatar
waynephRetrun Selection in DropDown Box to DataGrid wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

The e.Item.Cells collection will give you access to all of the Cells on the row. You can set up some of the formatting that way.

Otherwise in your code, You can use the <ItemStyle>, <AlternatingItemStyle> tags with in your DataGrid Definition. You should only have to use the Cells collection if they'll be changin on the fly. Otherwise, you should be able to do it declaritively where you create the DataGrid.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #24  
Old 12-08-2006, 01:49 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

I have tried using the <AlternatingItemStyle> and <ItemStyle> but that is not transferring the properties to the textbox that is dynamically generated on the Edit procedure.

I have also tried using the e.Item.Cells collection but no luck there either.... Do i need to called the .Controls(0) since I know the position? I have tried this but it does not allow the property .forecolor, or any other formatting properties... I am trying to do this under the edit_function, perhaps I will try the Item_Bound function as well.

The skinny of what I am trying to do is highlight the fields that can be updated in RED when the textbox appears with the values from the database..

Quote:
Originally Posted by wayneph
The e.Item.Cells collection will give you access to all of the Cells on the row. You can set up some of the formatting that way.

Otherwise in your code, You can use the <ItemStyle>, <AlternatingItemStyle> tags with in your DataGrid Definition. You should only have to use the Cells collection if they'll be changin on the fly. Otherwise, you should be able to do it declaritively where you create the DataGrid.
Reply With Quote
  #25  
Old 12-08-2006, 02:24 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

The more I think about this, the more I think I am going to have to convert all of the boundcolumns to templatecolumns.... I am not having luck anyother way...


Quote:
Originally Posted by mountainbiking
In ASP.NET I am trying to Return the Selection of a User's DropDown Box to Display that data in a datafield within the DataGrid.

I am just digging into ASP.Net so I don't know all of the rules vs. Classic ASP. The code I have right now is this:

<asp:BoundColumn DataField="<%Session("tblSelect")%>" HeaderText="Test">
</asp:BoundColumn>

By the errors I get:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the name '"Session("tblSelect")"' was not found on the selected data source.

I can assume you cannot bring Sessions into the HTML due to "spaghetti stringing'.

How can I display a custom value in the DG from a Dropdown box selection... BTW here is my code for the dropdown box and selectionchange:

Protected Sub FieldSelect_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If FieldSelect.SelectedValue = "Cell_Number" Then
Session("tblSelect") = "SID"
ElseIf FieldSelect.SelectedValue = "Switch_Number" Then
Session("tblSelect") = "Switch_Number"
End If
Call ShowDataGrid()
End Sub
Reply With Quote
  #26  
Old 12-08-2006, 03:06 PM
wayneph's Avatar
waynephRetrun Selection in DropDown Box to DataGrid wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

A template column would probably be the easiest. I don't know why e.Item.Cells(x).Controls(0) isn't helping. Have you used DirectCast to get it to the right type?
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #27  
Old 12-08-2006, 04:44 PM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

I have tried the DirectCast in the edit and item_bound events... but I am not sure if I was using the right formatting with the DirectCast... this time won't I call Cells(x).Controls(0) ? vs. Item.FindControl?

Thanks.. I have had a heck of a time with this.

Quote:
Originally Posted by wayneph
A template column would probably be the easiest. I don't know why e.Item.Cells(x).Controls(0) isn't helping. Have you used DirectCast to get it to the right type?
Reply With Quote
  #28  
Old 12-11-2006, 08:00 AM
wayneph's Avatar
waynephRetrun Selection in DropDown Box to DataGrid wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

without seeing what you've got it's going to be hard to guess what's going on...
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #29  
Old 12-11-2006, 10:02 AM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

Code:
Sub btnSearch_OnClick(sender as Object, e as EventArgs) dgPaging.CurrentPageIndex = 0 ShowDataGrid() End Sub Sub PageChange(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs) dgPaging.CurrentPageIndex = e.NewPageIndex ShowDataGrid() End Sub Sub dgPaging_Edit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs) ' dgPaging.EditItemIndex = E.Item.ItemIndex ' DirectCast(E.Item.FindControl(E.Item.Cells(3).Controls(0).ToString), TextBox).ForeColor = Drawing.Color.Blue ' E.Item.Cells(2).ForeColor = Drawing.Color.Red dgPaging.EditItemIndex = E.Item.ItemIndex ShowDataGrid() End Sub Sub dgPaging_Cancel(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs) dgPaging.EditItemIndex = -1 ShowDataGrid() End Sub Sub dgPaging_Update(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs) Dim intID As String = E.Item.Cells(1).Text Dim tbText As TextBox = E.Item.Cells(2).Controls(0) Dim tbInteger As TextBox = E.Item.Cells(3).Controls(0) objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data\vzwengineering.mdb")) objConnection.Open() ' Build our update command. strSQLQuery = "UPDATE " & Session("myTable") _ & " SET Cell_Name = '" & Replace(tbText.Text, "'", "''") & "', " _ & "Charge_Amount = " & tbInteger.Text & " " _ & "WHERE sid = " & intID & ";" ' Again... if you're not sure you've got the right command built... ' you can always check! Response.Write(strSQLQuery) ' Create new command object passing it our SQL query ' and telling it which connection to use. objCommand = New OleDbCommand(strSQLQuery, objConnection) ' Close our open DataReader objConnection.Close() Try ' Execute the command objConnection.Open() objCommand.ExecuteNonQuery() objConnection.Close() Catch Ex As Exception Response.Write("<p><strong>An Error Occurred:</strong> " & Ex.ToString() & "</p>" & vbCrLf) Response.Write("<p>Most likely you tried to enter data that was inappropriate.</p>" & vbCrLf) Response.Write("<ul>" & vbCrLf) Response.Write("<li>The text field is limited to 10 characters at the database level.</li>" & vbCrLf) Response.Write("<li>The integer field is a smallint... no text and only values from -32768 to 32767!</li>" & vbCrLf) Response.Write("<li>The datetime field must contain a string that can be converted to a valid Date / Time</li>" & vbCrLf) Response.Write("</ul>" & vbCrLf) Finally objConnection.Close() End Try ' Refresh our copy of the data LoadDataFromDB() ' Reset our current edit item and rebind the grid dgPaging.EditItemIndex = -1 ShowDataGrid() End Sub Sub ShowDataGrid() Dim objConnection As OleDbConnection Dim objCommand As OleDbCommand Dim objAdapter As OleDbDataAdapter Dim strSearch As String Dim strSQLQuery As String objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data\vzwengineering.mdb")) objConnection.Open() strSearch = txtSearch.Text If Session("myTable") = "" Then Session("myTable") = "tblSurvey" End If If Len(Trim(strSearch)) > 0 Then ' Set up our SQL query text. strSQLQuery = "SELECT * " _ & "FROM " & Session("myTable") & " " _ & "WHERE Cell_Name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _ & "ORDER BY Cell_Number;" Else strSQLQuery = "SELECT * " _ & "FROM " & Session("myTable") & ";" End If ' Create new command object passing it our SQL query ' and telling it which connection to use. objCommand = New OleDbCommand(strSQLQuery, objConnection) ' Get a DataSet to bind the DataGrid to objAdapter = New OleDbDataAdapter(objCommand) objDataSet = New DataSet() objAdapter.Fill(objDataSet, Session("myTable")) lblRecordCount.Text = objDataSet.Tables(Session("myTable")).Rows.Count ' DataBind DG to DS dgPaging.DataSource = objDataSet dgPaging.DataBind() Label2.Text = dgPaging.PageCount Label1.Text = dgPaging.CurrentPageIndex + 1 objConnection.Close() End Sub Protected Sub SelectArea_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) If SelectArea.SelectedValue = "tblSurvey" Then Session("myTable") = "tblSurvey" dgPaging.CurrentPageIndex = 0 Else Session("myTable") = "tblSurveyMD" dgPaging.CurrentPageIndex = 0 End If Call ShowDataGrid() End Sub Protected Sub FieldSelect_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Call ShowDataGrid() End Sub Sub Item_Bound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Item Or _ e.Item.ItemType = ListItemType.AlternatingItem Then Dim Price As Double = Convert.ToDouble(e.Item.Cells(3).Text) e.Item.Cells(3).Text = Price.ToString("c") End If If e.Item.ItemType = ListItemType.Item OrElse _ e.Item.ItemType = ListItemType.AlternatingItem OrElse _ e.Item.ItemType = ListItemType.SelectedItem Then DirectCast(e.Item.FindControl("Label3"), Label).Text = e.Item.DataItem(FieldSelect.SelectedValue).ToString End If If e.Item.ItemType = ListItemType.Header Then DirectCast(e.Item.FindControl("Label4"), Label).Text = FieldSelect.SelectedItem.Text End If If e.Item.ItemType = ListItemType.EditItem Then DirectCast(e.Item.FindControl("textbox1"), TextBox).ForeColor = Drawing.Color.Blue DirectCast(e.Item.FindControl("textbox1"), TextBox).Text = e.Item.DataItem(FieldSelect.SelectedValue).ToString DirectCast(e.Item.FindControl("DropDownList1"), DropDownList).SelectedValue = e.Item.DataItem(FieldSelect.SelectedValue).ToString End If End Sub 'Item_Bound </script>
HTML Code:
<asp:DataGrid id="dgPaging" runat="server"
  AllowPaging = "True"
  OnEditCommand   = "dgPaging_Edit"
  OnCancelCommand   = "dgPaging_Cancel"
  OnUpdateCommand   = "dgPaging_Update"
  OnPageIndexChanged = "PageChange" 
  OnItemDataBound="Item_Bound" 

  AutoGenerateColumns="False" style="font-size: 10pt; font-family: 'Trebuchet MS';" Height="146px" Width="453px" BorderColor="BlueViolet" BorderWidth="3px" CellPadding="5" GridLines="Horizontal" Font-Bold="False" Font-Italic="False" Font-AllowSorting="True" ShowFooter="True" ForeColor="Black" >
    <Columns>
        <asp:HyperLinkColumn DataNavigateUrlField="SID" DataNavigateUrlFormatString="default3.aspx?ID={0}"
            HeaderText="View Details" Target="_blank" Text="View"></asp:HyperLinkColumn>
        <asp:BoundColumn DataField="SID" HeaderText="ID" ReadOnly="True" Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Cell_Name" HeaderText="Cell Site Name" >
    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
        Font-Underline="False" ForeColor="Black" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Charge_Amount" HeaderText="Charge Amount" >
</asp:BoundColumn>
        <asp:TemplateColumn HeaderText="Custom Field">
            <ItemTemplate>

                 <asp:Label ID="Label3" runat="server" Font-Bold="True" ForeColor="Indigo" Text="Label"></asp:Label>
            </ItemTemplate>
            <HeaderTemplate>
                <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
            </HeaderTemplate>
            <EditItemTemplate>
                
                <% If FieldSelect.SelectedItem.Text = "Status" Then%>
                <asp:DropDownList ID="DropDownList1" runat="server">
                    <asp:ListItem>No Records</asp:ListItem>
                    <asp:ListItem>To be Surveyed - No 42.20</asp:ListItem>
                    <asp:ListItem>Assigned to be Surveyed</asp:ListItem>
                    <asp:ListItem>BO Creating Records</asp:ListItem>
                </asp:DropDownList>
                <%Else%>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <% end if %>
            </EditItemTemplate>
        </asp:TemplateColumn>
 
        <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" HeaderText="Edit"
            UpdateText="Update" >
            <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                Font-Underline="False" ForeColor="#0000CC" />
        </asp:EditCommandColumn>
        <asp:ButtonColumn CommandName="Select" Text="Select" DataTextField="SID" HeaderText="Select"></asp:ButtonColumn>
    </Columns>
</asp:DataGrid>

Last edited by wayneph; 12-11-2006 at 11:40 AM. Reason: disabled smilies and added tags for formatting
Reply With Quote
  #30  
Old 12-13-2006, 06:13 AM
mountainbiking's Avatar
mountainbiking mountainbiking is offline
Junior Contributor
 
Join Date: Oct 2002
Posts: 259
Default

Any update on this question? I have been looking in many places but still no luck...
Reply With Quote
  #31  
Old 12-13-2006, 08:17 AM
wayneph's Avatar
waynephRetrun Selection in DropDown Box to DataGrid wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

In all honesty, I'm completely lost on what the current question is... There are a couple things that look more like Classic ASP or PHP then .NET. Since moving to .NET, I have not used <% %> for inline code. So I would never have the "If...Then" statement in the aspx declaration. In your case you can do the exact same thing by toggleing the .Visible property in the back ground.

If I had to guess that's leading to your problem. Since only one of the controls in the edit template (DropDownList1 or Textbox1) will exist at any time, you can't access both of them together in your ItemBound method. Only one at a time could possibly work.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
 
Retrun Selection in DropDown Box to DataGrid
Retrun Selection in DropDown Box to DataGrid
 
-->