.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Pass Id To ObjectDataSource From DetailsView Control

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net

Hello all

I have an objectDataSource to retrieve data and fill a listBox on edit

I created a BLL method to get the data and set the controlId to the detailsVeiw control but the id is not passed throuh to the bll class

this is my code:

    <asp:ObjectDataSource ID="odsItems" runat="server" 
        SelectMethod="GetRecords" TypeName="BLL.GetData.Get">
            <asp:ControlParameter ControlID="detailsVeiw" Name="id" 
                PropertyName="SelectedValue" Type="Int32" />

    <asp:DetailsView ID="detailsVeiw" runat="server" AutoGenerateRows="False" DataSourceID="odsByKey" DataKeyNames="id">
            <asp:TemplateField HeaderText="Code" SortExpression="id">
                    <asp:Label ID="lblIdEdit" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
                    <asp:Label ID="lblIdItem" runat="server" Text='<%

View Complete Post

More Related Resource Links

what am i doing wrong with this objectdatasource that the DetailsView never gets populated


I want to allow the user to view and edit their information.

So using another example i found online, i got it work, but the example was setup for you to provide the user name and search for the person, since you are already logged into the system i want to pass your username into the code so that on page load the DetailView is populated with your details.

                      <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="UserName" DataSourceID="ObjectDataSource2" Width="400px">
                                <asp:BoundField DataField="PasswordQuestion" HeaderText="PasswordQuestion" ReadOnly="True" SortExpression="PasswordQuestion" />
                                <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName" />
                                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                                <asp:BoundField DataField="CreationDate" HeaderText="CreationDate" ReadOnly="True" SortExpression="Cre

Get value of a label control inside the DetailsView

Hi everyone, I have a databound label control (i.e. Label 3) inside an Item Template that's in a DetailsView control. I just need to get the value of those label and compare it to some string. I tried several ways (i.e. Find control, DetailsView.Row) but nothing seems to work. I don't know if I'm using the FindControl methos correctly or if I need to access the Row first and do the findcontrol method.  Protected Sub DetailsView4_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView4.DataBound 'If (DetailsView4.Rows(2).Cells(1).ToString = "Regular") Then 'Label3.ForeColor = Drawing.Color.Azure 'End If 'Dim StatusQualifierContainer As Label 'Dim S As String 'StatusQualifierContainer = DetailsView4.FindControl(Label3.Text) 'S = StatusQualifierContainer.Text 'If S = "Regular" Then 'Label5.ForeColor = Drawing.Color.Aqua 'End If 'Dim C As Label = DetailsView4.FindControl("Label3") 'If C.Text = "Regular" Then 'Label3.ForeColor = Drawing.Color.DarkBlue 'End If 'Dim headerRow As DetailsViewRow = DetailsView4.HeaderRow 'Dim lblText As Label = CType(headerRow.FindControl("Label3"), Label)

How to pass a control ID to a User Control

Dear guy,i am very new to asp.net and i am trying to make a pop-up messsage box, using popupControlExtender. Such extender will be inside a web user control but the target control will be outside the user control instead. Could anyone tell me how i can do it ? =========================================my user Control : UCPopUp.ascx<asp:Panel ID="pnlPopUp" runat="server" style="display:none" ><div class="clsPopUp" ><asp:Literal ID="lblPopUp" runat="server" Text="Pop up Message." /></div></asp:Panel>                                                                       <asp:PopupControlExtender ID="PCEPopUp" runat="server"                                                     TargetControlID="TxtMyControl" PopupControlID="pnlPopUp"  Position="Right" /> =================================================in the page,<asp:textbox id="txtMyControl" runat="server" text="" /><

Control this objectdatasource programatically from the code behind based on different button clicks

I have a page where you can search and display other data, very simple layout. 1 Gridview and 1 objectdatasource. But i have 4 possible buttons that can populate the gridview.. i would like to control my objectdatasource from the code behind based on the button you click. here is what i have right now.. but if possible, can this source not be hardcoded like this and only built in the code behind? <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectDVRInfo" TypeName="DataAccessCode"> <SelectParameters> <asp:ControlParameter ControlID="ddlDVR" Name="dvrInfo" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:ObjectDataSource> I found this site with a solution to this persons issue, but i cant seem to get mine working this way. http://stackoverflow.com/questions/2404264/overwriting-controlparameters-of-datasources-in-code-behind I have  this as the code behind right now when you press the button.. what other parameter settings am i missing and is this the right order to populate them for the source to acknowledge my values?   ObjectDataSource1.SelectMethod = "SelectDVRInfo"; ObjectDataSource1.SelectParameters["MyParameter"]

pass selected keyname to detailsView

Hello EveryoneI have a gridView and DetailsView.gridView.enabledselection=true. when I select a row I want to display that record in DetailsView.Can someone tell me how to di it?I have done it previously but after lot of php coding, I forgot it :S  can someone remind it to me?there is something datakeyname or something like this  parameters to specify

How to pass variable to objectDataSource???

Could someone please help me with this?I have an objectDataSource which uses my stored procedure GetNotificationsAnd my GridView is bound to that objectDataSourcethe only problem is that my stored procedure requires the variable @UserName and then returns the values for that username, but I do not know how to pass the variable to the objectDataSource, does anyone know the code for this?I can get userName from HttpContext.Current.User.Identity.Name but how do I pass that to the objectDataSource?

Pass Javacript to Custom Control with ClientID

Hello,Can someone help me with this.  I have a custom control that I have created.  I want to be able to pass in a Javascript snippet for a callback function.  I am able to do this by passing a string back.  The problem is that in the Javascript, I need to reference another server control that is not related to my custom control.  So, I need to be able to pass in the ClientID of that control for use in the Javascript.  Here is a snippet of what I am trying to do:<asp:CheckBox ID="chkStartDate" runat="server" /><cc:MyNewControl id="MyControl1" runat="server" OnClientOnChangeEvent="toggleCheckBox('<%= chkStartDate.ClientID %>');" /> Now, I realize that '<%= chkStartDate.ClientID %>' will not be parsed.  But, I need it to be parsed so the OnClientOnChangeEvent property of my custom control can take any Javascript for use as a callback. In this instance, I need to pass in the ClientID of the control for the Javascript function to find the control to work with; and this seems to be the one issue that I don't know how to handle. I would appreciate any help offered for this.Thanks in advance.

How to pass parameters via a button control

Hi all, I would like to pass a number of parameters via a button, (it must be a button) but I don't know how to do this, could someone please help. I've be grateful for any suggestions    

ObjectDataSource Control Disabled/not appearing in Toobox for Visual Studio 2010 SharePoint Project

  1. I've created a SharePoint Project in Visual Studio 2010.
  2. Added Visual webPart .
  3. In the usercontrol of the webpart in trying to add ObjectDataSource control, but this control is not availble in Tool box under Data tab. it appears only if i right click on datatab and select "Show All", but still the ObjectDataSource Control is Disabled and even i cannot drag and drop it on the Webpart.
  4. Also i've created a sample Business Class, with all the mandatory attribute like





How to pass value from browser into embedded windows form control library


Hi all,

i have one project which i embed the windows form control library inside the web form.

now i wanna pass a url from aspx into my windows form control library.

May i know how to do this?


updating problem with ObjectDataSource control


hi all, i got confused about updating method with ObjectDataSource control. Those parameters just a nightmare for me. I tried use those parameters implicitly and explicitly, but coudln't get it working.

The task is to update the data from txtIllness and txtDiagnosis according to selected consultationID.

Any helps are greatly apperciated.

Thank you

Here is the code

public class ShowConsultation
    private readonly string constring;
    string name = HttpContext.Current.User.Identity.Name;
    public ShowConsultation()
        constring = WebConfigurationManager.ConnectionStrings["SurgeryConnectionString"].ConnectionString;
    public SqlDataReader GetConsultation()

        SqlConnection con = new SqlConnection(constring);
        SqlCommand cmd=new SqlCommand();
        cmd.CommandText = "SELECT Consultation.consultationID,Consultation.Illness,Consultation.Diagnosis,Consultation.Date,Patient.firstName,Patient.lastName,Patient.DOB,Patient.suburb,Patient.postCode FROM Consultation,Practitioner,Patient WHERE Practitioner.UserName=@UserName AND Practitioner.GPNo=Consultation.GPNo AND Patient.patientID=Consultation.patientID";
        return cmd.ExecuteReader(Com

Can I use a DetailsView control to insert and update with RIA services?



I'm struggling with trying to use RIA services from an ASP.NET web site.

I created a new web site, added an entity framework model, then added a RIA service that uses that model. I used the DomainDataSource control to bind the ASP.NET controls to the RIA service.

I have a GridView that shows items from the database (via RIA and the entity framework model underneath it), and can see the items fine. I added a DetailsView as a pop-up, as shown in http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html and http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html. When I click the "edit" link in a row in the GridView, the DetailsView shows with the right data, but clicking the "save" link doesn't actually update the database.

Furthermore, I can't work out how to add new items this way, as when I try and use the DetailsView to add a new item, nothing is sent to the database.

Anyone any ideas how this can be done?


How to merge columns in DetailsView control?


I have a DetailsView control with two columns and 7 rows. I need the two columns to merge in row two and get rid of the header. I only the data from the DB to display no the header name in row two. How do I merge it in DetailsView control?

Help is much appreciated.

retrieve username from login control to pass it on as a parameter for poplulation of dropdown box.


Hi guys,

Would appreciate some help with this.

after a successful login I'd like to retrieve the users' name via C# and pass the name on as a parameter to populate a dropdown box or a grid view on the redirected page.

To authenticate a user I use the asp.net login control and I saw that I have access to several properties and methods but can't see text or value to just get the name back and pass it on for further processing.

Am I thinking wrong here?

Any hint on how to accomplish this is much appreciated.



DetailsView control boarder


Here's my DetailsView control:

<asp:DetailsView ID="dtvEvents" runat="server" AutoGenerateRows="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="id_eve" DataSourceID="sqlEventsDetails" Height="50px" Width="100%">
<FooterStyle BackColor="White" ForeColor="#000066" />
<EditRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<RowStyle ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />

The problem I have is the border lines in IE browser. In the picture below, the FF browser is the top and IE browser is on the bottom.

How do I get the DetailsView control broarder so that IE browser also have the same border showing up as in FireFox?

Any help is much appreciated.

Detailsview control needs to add records to mulitple tables


I've got a gridview and a detailsview control on my page. The detailsview is where new records are added. When a record is added to it.

My code looks like:


<asp:DetailsView AutoGenerateRows="False" DataKeyNames="EmployeeId" DataSourceID="SqlDataSourceEmpl1"

DefaultMode="Insert" HeaderText="Add Employee" ID="DetailsInsertEmployee" runat="server"

AutoGenerateInsertButton="true" OnItemInserting="DetailsInsertEmployee_ItemInserting"

OnItemInserted="DetailsInsertEmployee_ItemInserted" CellSpacing="2" >


<asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />

<asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />


<HeaderStyle BackColor="#513631" Font-Bold="True" ForeColor="#FFFFFF" />

<RowStyle BackColor="#E0C6C1" F

Find Control in DetailsView


hi all

i want to find a control (TextBox) in Detailsview using javascript

any idea...


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend