I am making an ASPx and C# form with DevExpress comboboxes and an SQL database. I've pulled the data to one of the boxes that I need.
I need to assign a variable to one of the fields from the database that are pulled into the combobox.
<dx:ASPxComboBox ID="testNameBox" runat="server" CssClass="dropdown"
Font-Names="Tahoma" Font-Size="10px" ClientIDMode="AutoID"
DataSourceID="testSource" ValueType="System.String"
IncrementalFilteringMode="Contains">
<Columns>
<dx:ListBoxColumn FieldName="pkTestKey" Visible="False" />
<dx:ListBoxColumn FieldName="fkTestCode" Visible="False" />
<dx:ListBoxColumn Caption="Test Item Name" FieldName="Name" />
</Columns>
</dx:ASPxComboBox>
The point is that when I choose something in this combobox, another combobox displays related data from another table based on the fkCode value.
How would I pull that variable from this, and use it so that my query for the textbox displays the appropriate data based on that fkCode?
Take a look at this demo on DevExpress. You might want to search more about Cascading Comboboxes
<script>alert("demo for XSS")</script>
Related
This question may look repeating but I'm having a slightly different challenge. I have a GridView with multiple columns. The first column is a Button column and the rest are populated from the database.
Problem Statement:
When a user clicks the Edit button on a specific row, a TextBox should appear in the column called UnitRate in the GridView gv2. The default text of the TextBox should be the value / text of that same cell. This TextBox should appear only for that specific cell not for the entire column. The current GridView is shown below.
And I want something like this
Code for GridView
<asp:GridView ID="gv2" runat="server" Font-Size="Small" OnRowCommand="gv2_RowCommand">
<HeaderStyle BackColor="Yellow" />
<AlternatingRowStyle BackColor="LightGray" />
<RowStyle BackColor="LightGray" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btn_edit" runat="server" Text="Edit" CssClass="btn btn-warning btn-sm" CommandName="editData" CommandArgument='<%# Container.DisplayIndex %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns></asp:GridView>
You can try something like this: https://www.c-sharpcorner.com/UploadFile/1e050f/edit-and-update-record-in-gridview-in-Asp-Net/
You can use the EditItemTemplate to make that UnitRate field a text box when the user clicks edit. You can then make the EditItemTemplate for all the rest of the fields to just be a label. The drawback is that you have to spell out all the columns explicitly rather than having them autogenerated, but that's unavoidable if you want something non-standard like this to happen, where one field is editable while others aren't.
I'm working on a legacy windows forms project which I'm migrating to webforms.
There is a dataset which I bind to a gridview .
I have made all boundfields, so the gridview won't automatically generate the columns. Whenever I bind this dataset to the grid, some columns are missing in the dataset, so it's throwing errors about inexistent columns.
Is there any way to ignore missing columns in bound fields? Like, remove the bound column if it doesn't exist... or just ignore it?
I had to use a different approach:
I set the gridview to have no columns and autogeneratecolumns to false.
Then I created a XML with the list of all possible columns (this is a XML, not asp.net markup)
<Grid ID="grdSenha">
<BoundField HeaderText="Status" />
<BoundField DataField="Flg_Imprimiu" HeaderText="Imprimiu?" Visible="True" />
<BoundField DataField="Nom_Localdest" HeaderText="Local Descarga" Visible="True" />
<BoundField DataField="Dsc_Localdest" HeaderText="Descrição" Visible="True" />
<BoundField DataField="Cod_Produto" HeaderText="Cod Prod" Visible="False" />
<BoundField DataField="Dsc_Produto" HeaderText="Descrição Produto" Visible="True" />
<BoundField DataField="Qtd_Transport" HeaderText="Qtde" Visible="True" />
<BoundField DataField="Cod_Transport" HeaderText="Cod Trans" Visible="False" />
[...]
</Grid>
Then, in my code, I'd select from the XML only the columns present in my datasource (using the DataField as key), then create the bound fields accordingly.
It works perfectly.
This combo box is in an asp.net page and the intention is to bind it to a nvarchar(50).
The user select one of the values and then update the DB.
<telerik:RadComboBox ID="RadComboBox1" runat="server" SelectedValue='<%# Bind("inBudgetTT") %>'>
<Items>
<telerik:RadComboBoxItem Text="In Budget" />
<telerik:RadComboBoxItem Text="Not In Budget" />
</Items>
</telerik:RadComboBox>
The problem: doesn't matter what I select, it is never written in the DB. Any hint on how to solve the problem?
Use the SelectedIndexChanged event to update your database: http://www.telerik.com/help/aspnet-ajax/combobox-server-side-selectedindexchanged.html. The SelectedValue property only indicates what the control should show as a selected item.
I currently have a gridview that is set up and working properly but I ran into a little bit of an issue. My grid's datasource is being set from a DB table and one of the columns in the table is the numeric ID of another table. Rather than displaying this numeric ID in the grid, I need to display a description column off of the other table. Can I add an additional column to my current gridview just for display purposes?
Yes you can accomplish this by using a template on your ID field rather than creating a new field. This link has some examples. This way you can custom format your existing column.
You can use a data-set and bind this dataset to the gridview.
Using the data-set, you can add rows, columns. The below example is a good one to add rows/columns to the grid-view. You can also follow the same example with a little bit of tweaks.
http://www.codeproject.com/KB/aspnet/dynamic_Columns_in_Grid.aspx
Set AutoGenerateColumns to false, and define the columns that you want to display:
<asp:GridView ID="GridView1" runat="server" CellPadding="4" CellSpacing="0" AutoGenerateColumns="false" Width="100%">
<RowStyle BackColor="#ffffff" />
<AlternatingRowStyle BackColor="#f5f5dc" />
<HeaderStyle BackColor="Beige" ForeColor="#333333" Font-Bold="true" Height="25px" />
<Columns>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<%# Eval("Address") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The change should be made in 3 locations:
The datasource should have the desc column brought back with it. Do the join in the database and bring it all back at once so the front end will not need to make an insane amount of calls.
On display, you can set the id column to invisible. This can be done on the code behind or on the aspx.
On edit, if it is a value that is based off of a look-up table, you will need to create a drop down list. You can query for more info if edit is needed, if not, the top two points should cover your needs.
I am creating a GridView/DetailsView page. I have a grid that displays a bunch of rows, when a row is selected it uses a DetailsView to allow for Insert/Update.
My question is what is the best way to link these? I do not want to reach out to the web service again, all the data i need is in the selected grid view row. I basically have 2 separate data sources that share the same "DataObjectTypeName", the first data source retrieves the data, and the other to do the CRUD.
What is the best way to transfer the Selected Grid View row to the Details View? Am I going to have to manualy handle the Insert/Update events and call the data source myself?
Is there no way to link these two so they use the same data source ?
<asp:GridView ID="gvDetails" runat="server" DataKeyNames="ID, Code"
DataSourceID="odsSearchData" >
<Columns>
<asp:BoundField DataField="RowA" HeaderText="A" SortExpression="RowA" />
<asp:BoundField DataField="RowB" HeaderText="B" SortExpression="RowB" />
<asp:BoundField DataField="RowC" HeaderText="C" SortExpression="RowC" />
....Code...
<asp:DetailsView ID="dvDetails" runat="server" DataKeyNames="ID, Code"
DataSourceID="odsCRUD" GridLines="None" DefaultMode="Edit" AutoGenerateRows="false"
Visible="false" Width="100%">
<Fields>
<asp:BoundField DataField="RowA" HeaderText="A" SortExpression="RowA" />
<asp:BoundField DataField="RowB" HeaderText="B" SortExpression="RowB" />
<asp:BoundField DataField="RowC" HeaderText="C" SortExpression="RowC" />
...
The standard way to do it would be to have the selected item of the griview be a control parameter to the objectdatasource you have wired up to the detailsview. I would probably not worry too much about the overhead of retreiving data that you already have unless you are catering to users with such slow connections that you want to avoid roundtrips to the webserver at all costs.
If you really want to avoid that thenyou could pull the data out of the gridview using javascript/jquery and then do your inserts/updates via ajax calls. It would require lots more coding though.
This is a really old thread, but in case anyone came here looking for an answer like I did, a simple solution is to add this function to your code:
(Note that this only works if the rows in your GridView match the entries in your DetailsView.)
protected void GridView1_OnSelectedIndexChanged(object sender, EventArgs e)
{
DetailsView1.SetPageIndex(GridView1.SelectedIndex);
}
And modify the GridView and DetailsView to include these settings:
<asp:GridView ... OnSelectedIndexChanged="GridView1_OnSelectedIndexChanged" ... >
<asp:DetailsView ... AllowPaging="True" ... >
This will make the selected page in the DetailsView match the selected index in the GridView.
You can hide the paging options in the DetailsView properties if you dont want users to navigate using paging in the DetailsView.