473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to get value from Boundfield in detailsview

1
I am trying to retrieve values from a boundfield in a detailsview.

protected void BtnViewDetails_Click(object sender, EventArgs e)
{
// get the gridviewrow from the sender so we can get the datakey we need
Button btnDetails = sender as Button;
GridViewRow row = (GridViewRow)btnDetails.NamingContainer;
DropDownList ddl = ((DropDownList)dvVehicleDetail.FindControl("Dropdo wnList1"));


// extract the vehicleid from the row whose details button originated the postback.
// grab the vehicleid and feed it to the vehicle details datasource
// finally, rebind the detailview
this.sqldsVehicleDetails.SelectParameters.Clear();
this.sqldsVehicleDetails.SelectParameters.Add("VID ", Convert.ToString(this.gvVehicles.DataKeys[row.RowIndex].Value));
this.dvVehicleDetail.DataSource = this.sqldsVehicleDetails;

this.dvVehicleDetail.DataBind();
this.updPnlVehicleDetail.Update();
// show the modal popup
this.mdlPopup.Show();

}
</Script>

<form id="form1" runat="server">
<table width="80%" align="center">
<tr>
<td>
<asp:ScriptManager ID="scriptManager" runat="server" />
<div>
<asp:SqlDataSource ID="sqldsVehicles" runat="server"
SelectCommand="SELECT VID,SERVICE_VIN,YR,MAKE,MODEL,STOCK_NO FROM tblImported_Bad_HONDA"
SelectCommandType="Text" ConnectionString="<%$ ConnectionStrings:keelerConnString %>" />
<asp:SqlDataSource ID="sqldsVehicleDetails" runat="server"
SelectCommand="select * from tblImported_Bad_HONDA where VID=@VID"
SelectCommandType="Text" CancelSelectOnNullParameter="true" ConnectionString="<%$ ConnectionStrings:keelerConnString %>"/>

<p style="background-color:AliceBlue; width:95%">
Please select a record below and edit the details.<br />
</p>

<br />
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTitle" runat="server" Text="Vehicle records with errors " BackColor="lightblue" Width="95%" />
<asp:GridView
ID="gvVehicles" runat="server" DataKeyNames="VID" AutoGenerateColumns="false"
AllowPaging="true" AllowSorting="true" PageSize="10" DataSourceID="sqldsVehicles" Width="95%">
<AlternatingRowStyle BackColor="aliceBlue" />
<HeaderStyle HorizontalAlign="Left" />
<Columns>
<asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px">
<ItemTemplate>
<asp:Button ID="btnViewDetails" runat="server" Text="Details" OnClick="BtnViewDetails_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SERVICE_VIN" HeaderText="VIN" SortExpression="SERVICE_VIN" ReadOnly="true" />
<asp:BoundField DataField="YR" HeaderText="Year" SortExpression="YR" ReadOnly="true" />
<asp:BoundField DataField="MAKE" HeaderText="Vehicle Make" SortExpression="MAKE" ReadOnly="true" />
<asp:BoundField DataField="MODEL" HeaderText="Vehicle Model" SortExpression="MODEL" ReadOnly="true" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button id="btnShowPopup" runat="server" style="display:none" />
<ajaxToolKit:ModalPopupExtender
ID="mdlPopup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlPopup"
CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server" Width="500px" style="display:none">
<asp:UpdatePanel ID="updPnlVehicleDetail" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblVehicleDetail" runat="server" Text="Vehicle Detail" BackColor="lightblue" Width="95%" />
<asp:DetailsView ID="dvVehicleDetail" AutoGenerateRows="false" DefaultMode="Edit" runat="server" Width="95%" BackColor="white" OnItemUpdating="cmdUpdate">
<Fields>
<asp:BoundField DataField="SERVICE_VIN" HeaderText="VIN" ReadOnly="false" SortExpression="SERVICE_VIN" />
<asp:BoundField DataField="YR" HeaderText="Vehicle Year" ReadOnly="false" SortExpression="YR" />
<asp:BoundField DataField="MAKE" HeaderText="Vehicle Make" ReadOnly="false" SortExpression="MAKE" />
<asp:TemplateField HeaderText="Vehicle Model">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource1" DataTextField="model" DataValueField="model"
AppendDataBoundItems="true" CausesValidation="false">
<asp:listitem value="-1">Please select a value</asp:listitem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:keelerConnString %>"
SelectCommand="SELECT DISTINCT Name as model FROM tblModel WHERE MakeID = 27">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate >
<asp:Label Runat="server" Text='<%# Bind("model") %>' ID="Label2"></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Vehicle Color">
<EditItemTemplate>
<asp:DropDownList ID="ColorDropDownList" runat="server" AutoPostBack="true"
DataSourceID="SqldsColor" DataTextField="LongName" DataValueField="ShortName"
AppendDataBoundItems="true" CausesValidation="false">
<asp:listitem value="-1">Please select a value</asp:listitem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqldsColor" runat="server" ConnectionString="<%$ ConnectionStrings:keelerConnString %>"
SelectCommand="SELECT DISTINCT ShortName, LongName FROM tblColors ">
</asp:SqlDataSource>
</EditItemTemplate>
</asp:TemplateField>

<asp:BoundField HeaderText="Vehicle Miles" DataField="MILES" ReadOnly="false" SortExpression="MILES" />
<asp:BoundField HeaderText="Vehicle Price" DataField="LIST" ReadOnly="false" SortExpression="LIST" />

<asp:BoundField HeaderText="Stock No" DataField="STOCK_NO" ReadOnly="false" SortExpression="STOCK_NO" />
</Fields>
</asp:DetailsView>
<div align="right" style="width:95%">
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="ValidateBtn_OnClick" Width="50px" />
<asp:Button ID="btnClose" runat="server" Text="Close" OnClick="CloseBtn_OnClick" Width="50px" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</div>
</td>
</tr>
</table>
</form>
Mar 3 '08 #1
0 4584

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sck10 | last post by:
Hello, I am trying to change a value when a user goes into edit mode on a DetailsView control. I am trying to use the following, but can not figure out how to get to the bound field...
5
by: sck10 | last post by:
Hello, I am using the code below to set the values of a DetailsView template field using FindControl. My question is how would you find a control if its a Boundfield control? For example,...
0
by: André | last post by:
Hi, I want I defined a detailsview connected to a datasource. The purpose is: when an user clicks into a particular field (when the focus is on that field), something must happen.My problem is:...
0
by: John Mason | last post by:
Hi, I am trying to find out if there is a way to set the headertext of the boundfield column belonging to a detailsview control (ASP.NET 2.0), from code. <asp:BoundField HtmlEncode="false"...
0
by: miketayloruk | last post by:
I'm using a detailsview control that I want to use to insert data to a table. One of the fields is a date field and I want that to default to todays date. In classic asp I would do it like this: ...
3
by: dhaneshrs | last post by:
I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only. Say i have a table Employee with the following...
2
by: mohaaron | last post by:
Why does it seem like is impossible to set the width of a BoundField in a GridView. I've tried all sorts of different way to set the width and none of them work. So far the only thing I've done...
2
by: bob | last post by:
Hi, the detailsview (default mode = insert) is used to introduce names into the database. I need in code-behind the introduced name. I tried this: <asp:DetailsView ID="DetailsView1"...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.