473,770 Members | 4,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get value from Boundfield in detailsview

1 New Member
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)bt nDetails.Naming Container;
DropDownList ddl = ((DropDownList) dvVehicleDetail .FindControl("D ropdownList1")) ;


// 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.sqldsVehic leDetails.Selec tParameters.Cle ar();
this.sqldsVehic leDetails.Selec tParameters.Add ("VID", Convert.ToStrin g(this.gvVehicl es.DataKeys[row.RowIndex].Value));
this.dvVehicleD etail.DataSourc e = this.sqldsVehic leDetails;

this.dvVehicleD etail.DataBind( );
this.updPnlVehi cleDetail.Updat e();
// show the modal popup
this.mdlPopup.S how();

}
</Script>

<form id="form1" runat="server">
<table width="80%" align="center">
<tr>
<td>
<asp:ScriptMana ger ID="scriptManag er" runat="server" />
<div>
<asp:SqlDataSou rce ID="sqldsVehicl es" runat="server"
SelectCommand=" SELECT VID,SERVICE_VIN ,YR,MAKE,MODEL, STOCK_NO FROM tblImported_Bad _HONDA"
SelectCommandTy pe="Text" ConnectionStrin g="<%$ ConnectionStrin gs:keelerConnSt ring %>" />
<asp:SqlDataSou rce ID="sqldsVehicl eDetails" runat="server"
SelectCommand=" select * from tblImported_Bad _HONDA where VID=@VID"
SelectCommandTy pe="Text" CancelSelectOnN ullParameter="t rue" ConnectionStrin g="<%$ ConnectionStrin gs:keelerConnSt ring %>"/>

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

<br />
<asp:UpdatePane l ID="updatePanel " runat="server" UpdateMode="Con ditional">
<ContentTemplat e>
<asp:Label ID="lblTitle" runat="server" Text="Vehicle records with errors " BackColor="ligh tblue" Width="95%" />
<asp:GridView
ID="gvVehicles " runat="server" DataKeyNames="V ID" AutoGenerateCol umns="false"
AllowPaging="tr ue" AllowSorting="t rue" PageSize="10" DataSourceID="s qldsVehicles" Width="95%">
<AlternatingRow Style BackColor="alic eBlue" />
<HeaderStyle HorizontalAlign ="Left" />
<Columns>
<asp:TemplateFi eld ControlStyle-Width="50px" HeaderStyle-Width="60px">
<ItemTemplate >
<asp:Button ID="btnViewDeta ils" runat="server" Text="Details" OnClick="BtnVie wDetails_Click" />
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="SERV ICE_VIN" HeaderText="VIN " SortExpression= "SERVICE_VI N" ReadOnly="true" />
<asp:BoundFie ld DataField="YR" HeaderText="Yea r" SortExpression= "YR" ReadOnly="true" />
<asp:BoundFie ld DataField="MAKE " HeaderText="Veh icle Make" SortExpression= "MAKE" ReadOnly="true" />
<asp:BoundFie ld DataField="MODE L" HeaderText="Veh icle Model" SortExpression= "MODEL" ReadOnly="true" />
</Columns>
</asp:GridView>
</ContentTemplate >
</asp:UpdatePanel >
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button id="btnShowPopu p" runat="server" style="display: none" />
<ajaxToolKit:Mo dalPopupExtende r
ID="mdlPopup" runat="server" TargetControlID ="btnShowPop up" PopupControlID= "pnlPopup"
CancelControlID ="btnClose" BackgroundCssCl ass="modalBackg round" />
<asp:Panel ID="pnlPopup" runat="server" Width="500px" style="display: none">
<asp:UpdatePane l ID="updPnlVehic leDetail" runat="server" UpdateMode="Con ditional">
<ContentTemplat e>
<asp:Label ID="lblVehicleD etail" runat="server" Text="Vehicle Detail" BackColor="ligh tblue" Width="95%" />
<asp:DetailsVie w ID="dvVehicleDe tail" AutoGenerateRow s="false" DefaultMode="Ed it" runat="server" Width="95%" BackColor="whit e" OnItemUpdating= "cmdUpdate" >
<Fields>
<asp:BoundFie ld DataField="SERV ICE_VIN" HeaderText="VIN " ReadOnly="false " SortExpression= "SERVICE_VI N" />
<asp:BoundFie ld DataField="YR" HeaderText="Veh icle Year" ReadOnly="false " SortExpression= "YR" />
<asp:BoundFie ld DataField="MAKE " HeaderText="Veh icle Make" ReadOnly="false " SortExpression= "MAKE" />
<asp:TemplateFi eld HeaderText="Veh icle Model">
<EditItemTempla te>
<asp:DropDownLi st ID="DropDownLis t1" runat="server" AutoPostBack="t rue"
DataSourceID="S qlDataSource1" DataTextField=" model" DataValueField= "model"
AppendDataBound Items="true" CausesValidatio n="false">
<asp:listitem value="-1">Please select a value</asp:listitem>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:keelerConnSt ring %>"
SelectCommand=" SELECT DISTINCT Name as model FROM tblModel WHERE MakeID = 27">
</asp:SqlDataSour ce>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label Runat="server" Text='<%# Bind("model") %>' ID="Label2"></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>

<asp:TemplateFi eld HeaderText="Veh icle Color">
<EditItemTempla te>
<asp:DropDownLi st ID="ColorDropDo wnList" runat="server" AutoPostBack="t rue"
DataSourceID="S qldsColor" DataTextField=" LongName" DataValueField= "ShortName"
AppendDataBound Items="true" CausesValidatio n="false">
<asp:listitem value="-1">Please select a value</asp:listitem>
</asp:DropDownLis t>
<asp:SqlDataSou rce ID="SqldsColor " runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:keelerConnSt ring %>"
SelectCommand=" SELECT DISTINCT ShortName, LongName FROM tblColors ">
</asp:SqlDataSour ce>
</EditItemTemplat e>
</asp:TemplateFie ld>

<asp:BoundFie ld HeaderText="Veh icle Miles" DataField="MILE S" ReadOnly="false " SortExpression= "MILES" />
<asp:BoundFie ld HeaderText="Veh icle Price" DataField="LIST " ReadOnly="false " SortExpression= "LIST" />

<asp:BoundFie ld HeaderText="Sto ck No" DataField="STOC K_NO" ReadOnly="false " SortExpression= "STOCK_NO" />
</Fields>
</asp:DetailsView >
<div align="right" style="width:95 %">
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="Valida teBtn_OnClick" Width="50px" />
<asp:Button ID="btnClose" runat="server" Text="Close" OnClick="CloseB tn_OnClick" Width="50px" />
</div>
</ContentTemplate >
</asp:UpdatePanel >
</asp:Panel>
</div>
</td>
</tr>
</table>
</form>
Mar 3 '08 #1
0 4630

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

Similar topics

1
4439
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 ("MyBoundField") to set its new value. Any help with this would be appreciated. Sub EmployeeDetailView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs) Select Case CustomerDetailView.CurrentMode
5
23302
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, how would I reference the following BoundField ("NTAccount") in the Sub dvDetail_PreRender sub? Any help would be appreciated... <asp:BoundField DataField="NTAccount" HeaderText="NT Account" />
0
1360
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: how to get that field in javascript, because i can't define an 'ID' for a boundfield. <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" etc .../>
0
1517
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" DataFormatString="{0:###0.00}" DataField="wage_cash" HeaderText='<%# Format_Header("wage1") %>' SortExpression="wage_cash" />
0
1861
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: <input name="textfield" type="text" value="<%=now()%>" /> How do I do this in ASP.NET, heere is my current code: <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="data_key"
3
2068
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 columns : EmpID, Emp Name, Password, Emp Type. Now when i remove the value EmpID, the gridview does not update. it just reloads when i hit update but no changes are made. On the other hand say i make Emp Type as Read only, when i update .. the...
2
11259
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 that has worked is to set the Wrap property to false which is not what I want do. Can anyone tell me now to set the column width of a GridView in the aspx file code?
2
2389
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" runat="server" DefaultMode="Insert" > <Fields> <asp:BoundField DataField="name" />
4
2907
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 is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.