Category Archives: DetailsView

[RESOLVED] DropDown List Selection to Populate TextBox

How do i display sql data in the textfield based on selection. How can i display SQL data in the textfield box based DropDown selection. 
I want to display student first_name,last_name,dept on textfield box based on their ID number from DropDown selection.
How can i do that with ASP.NET?

You need to have a dropdownlist, populated by sqlDataSource Name = NameField ID = IDField Then Formview and SqlDatasource Second SqlDataSource when you set up your SqlDataSource SelectParameters use A ControlParameter that is the ID of the DropDownList.SelectedValue so Please Select a Student ID Obviously some of these items might be named differently, but this should be close enough to recognize what to do. You can also do this in code as well, but you should get the picture, The textbox is filled by whatever the selected Item is in the dropdownlist, you might also have to add a list item because you cannot select the first ID on the list. Let me know if you need more help

<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" 

    OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){

            //Do you Data Filling Logic

            //TextBox2.Text="ABC";

}

Hi, I hope this can help, but the basic is to get the student table using sqldatasource, linq, DataSet or your personel connection. when it's done and supposing you have DDL filled with data manually , what you remain is just to iterate through the table and fill the TxtBox with correct row in one of this events: SelectedIndexChanged and TextChanged you could try this example. http://aspalliance.com/581 Regards

I have a Text Box where user input their barcode. Based on that text box i want to populate other TextBoxes fields and DropDownList such as

their first name,last name and the dept that they work for. Can you please show me how to write the code with ASP.NET VB. Thank you for your helps.

Barcode(TextBox) --------->Fname(textbox) Lname(textbox) Dept(DropDownList)

Autopostback property of BARCODE textbox make true. then double click on this textbox, u will get codebehind .. and put code like this

SqlDataAdapter adp=new SqlDataAdpater("Select * from urtablename where barcodeid='"+txtbacode.Text+"',con);

fill it in dataset

adp.Fill(ds,"abc")

now read from datsaset

I want to populate other text boxes based on Barcode TextBox. When i input data to Barcode(Textbox),it doesnt populate data in the other text boxes such as Fname(textbox),Lname(Textbox) and Dept(Textbox). Iam new to asp.net. I dont know if iam doing it right..Please help..Please show me

the correct way to write this code. Thank you

 

<form id="form1" runat="server">

<p>

    <asp:TextBox ID="Barcode" runat="server" AutoPostBack="True"></asp:TextBox>

    <br />

    <asp:TextBox id="TextBox4" runat="server" DataSourceID="SqlDataSource1"

        DataField="Fname"  ></asp:TextBox>

    <asp:TextBox id="TextBox5" runat="server" DataSourceID="SqlDataSource1"

        DataField="Lname" ></asp:TextBox>

    <asp:TextBox id="TextBox6" runat="server" DataSourceID="SqlDataSource1"

        DataField="Dept" ></asp:TextBox>

   

     <asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="SELECT DISTINCT [Fname], [Lname], [Dept] FROM [frc_Database] WHERE ([Bar_id] = @Bar_id)">

        <SelectParameters>

            <asp:ControlParameter ControlID="Barcode" Name="Bar_id" PropertyName="Text"

                Type="String" />

        </SelectParameters>

    </asp:SqlDataSource>

</p>

</form>

Hi Spy

I think that you need to understand the environement that you work with, cause there are specefic bindable controls in the ToolBox like

detailview, repeater..etc fro that matter.

so for your current need, you must work with TxtBox's TextChanged event and retrieve data from sqlserver using your wizard SqlDataSource

filling each textbox with the appropriate field.

NB: an ASP.NET book is required

Try with Details View - 

http://www.learn-asp.net/ASPTutorials/DetailsView.aspx

Thanks.

Hi,

spyxdaxworld

  <asp:TextBox ID="Barcode" runat="server" AutoPostBack="True"></asp:TextBox>

    <br />

    <asp:TextBox id="TextBox4" runat="server" DataSourceID="SqlDataSource1"

        DataField="Fname"  ></asp:TextBox>

    <asp:TextBox id="TextBox5" runat="server" DataSourceID="SqlDataSource1"

        DataField="Lname" ></asp:TextBox>

    <asp:TextBox id="TextBox6" runat="server" DataSourceID="SqlDataSource1"

        DataField="Dept" ></asp:TextBox>

   

     <asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

        SelectCommand="SELECT DISTINCT [Fname], [Lname], [Dept] FROM [frc_Database] WHERE ([Bar_id] = @Bar_id)">

        <SelectParameters>

            <asp:ControlParameter ControlID="Barcode" Name="Bar_id" PropertyName="Text"

                Type="String" />

        </SelectParameters>

    </asp:SqlDataSource>

Sqldatasource can not fire the select query automatically when you changed text in texbox.

If you want to populate the data in other textbox based on one specific textbox by using sqldatabase.

You can check this, I modified some code accroding to your requirement. Hope you can get some ideas from it.

aspx:

<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] WHERE [CategoryID] = @CategoryID"
            <SelectParameters>
                <asp:Parameter Name="CategoryID" DbType="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>

 

aspx.cs:

 

  protected void Page_Load(object sender, EventArgs e)
        {

        }



         protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            this.SqlDataSource1.SelectParameters.Clear();
            this.SqlDataSource1.SelectParameters.Add("CategoryID", DbType.Int32, this.TextBox1.Text);
            DataView dv = SqlDataSource1.Select(DataSourceSelectArguments.Empty) as DataView;
            if (dv != null)
            {
                this.TextBox2.Text = dv.Table.Rows[0]["CategoryName"].ToString();
            }

        }

 

TextBox2 will populate data after TextBox1's text changedand lose focus on it. 

I used the northwind database, you can modify it whatever you need.

Hope this can help you

i ran the code it gives me an error  " 'bar_id_TextChanged' is not member of 'ASP.default_aspx'. "

What am i doing wrong?? My code is below

<asp:TextBox ID="bar_id" runat="server" AutoPostBack="True" OnTextChanged="bar_id_TextChanged"></asp:TextBox>

<asp:TextBox ID="dept" runat="server"></asp:TextBox>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

    SelectCommand="SELECT DISTINCT [Bar_id], [Fname] FROM [frc_database] WHERE ([bar_id] = @bar_id)">

    <SelectParameters>

    <asp:Parameter Name="bar_id" DbType="Int32" />

    </SelectParameters>

</asp:SqlDataSource>

 

Hi,

Make sure the event "OnTextChanged" has added in your code behind

Like:

aspx:

<asp:TextBox ID="bar_id" runat="server" AutoPostBack="True" OnTextChanged="bar_id_TextChanged"></asp:TextBox>

 

Code behind:

protected void bar_id_TextChanged(object sender, EventArgs e)
        {
                //code...
        }

Or another way you can add this event in code-behind to see if it make sense.

aspx:

 <asp:TextBox ID="bar_id" runat="server" ></asp:TextBox>

aspx.cs:

 protected void Page_Load(object sender, EventArgs e)
        {
            this.bar_id.AutoPostBack = true;
            this.bar_id.TextChanged += new EventHandler(bar_id_TextChanged);
        }



        protected void bar_id_TextChanged(object sender, EventArgs e)
        {
           //code...
        }

[RESOLVED] Dynamically change an SQL statement

I'd like to have a standard sql select statement that depending on user input changes to alternative one.

I've written code similar to this:

if (something is true....)

{
SQLdataSRC1.SelectCommand = "Select *...  etc";

// where SQLdataSRC1 is the name of the sql select statement datasource in the front end code.
}

I've put this code in the onload event and in the SQL datasource event handler but still it gets ignored - and only the SQL select statement in the front end code is recognised.

What am I doing wrong?

Can you show how the two different options compare? And where exactly within the code-behind have you put your conditional code?

 

I think best place to alter the SELECT Command is the SQLDataSource Selecting event.

I seem to have fixed it.

I was adding the new select statement to the onSelecting event - and I discovered that if I add the code to the onLoad event that it seems to work. Take a look at the code I have pasted below.

--------------------------------------------------------------------------------------

protected void Page_Load(object sender, EventArgs e)
    {
        if
           (Request.QueryString["LinkID"] == "11")
        {
            AccessDataSource2.SelectCommand = "SELECT * FROM [BizSales] WHERE ([id] = 170)";
        }
        if
          (Request.QueryString["LinkID"] == "12")
        {
            AccessDataSource2.SelectCommand = "SELECT * FROM [BizSales] WHERE ([id] = 165)";
        }

    }

-----------------------------------------------------------------------------------------------

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
        DataKeyNames="id" DataSourceID="AccessDataSource2" Height="50px"
        onpageindexchanging="DetailsView1_PageIndexChanging" Width="125px">
        <Fields>
            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
                ReadOnly="True" SortExpression="id" />
            <asp:BoundField DataField="AdType" HeaderText="AdType"
                SortExpression="AdType" />
            <asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
                SortExpression="CompanyName" />
            <asp:BoundField DataField="BodyTxt" HeaderText="BodyTxt"
                SortExpression="BodyTxt" />
            <asp:BoundField DataField="WebLink" HeaderText="WebLink"
                SortExpression="WebLink" />
            <asp:BoundField DataField="Logo" HeaderText="Logo" SortExpression="Logo" />
            <asp:BoundField DataField="Ranking" HeaderText="Ranking"
                SortExpression="Ranking" />
            <asp:BoundField DataField="DateAdded" HeaderText="DateAdded"
                SortExpression="DateAdded" />
            <asp:BoundField DataField="RemovalDate" HeaderText="RemovalDate"
                SortExpression="RemovalDate" />
            <asp:BoundField DataField="StartDate" HeaderText="StartDate"
                SortExpression="StartDate" />
        </Fields>
    </asp:DetailsView>
    <asp:AccessDataSource ID="AccessDataSource2" runat="server"
        DataFile="~/App_Data/Biz.mdb" 
        SelectCommand="SELECT * FROM [BizSales] WHERE ([id] = 160)"
        onselecting="AccessDataSource2_Selecting1">
   </asp:AccessDataSource>

Save yourself a ton of grief in future and use parameters.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.querystringparameter.aspx

 

Thanks Mike, but could you think of a reason why it only works in the onload event and not in the selecting event?

The only reason I can think of is that the selecting event isn't being fired. And the only reason for that is if it isn't properly hooked up to the datasource control.

Put a breakpoint on the Selecting event in your code behind and see if execution halts when you press F5. If it does, hit F10 to step through the code line by line and see if anything obvious jumps out in your Locals window.

 

Thanks, I give it a go.

[RESOLVED] How to display other control in same page

Hi!

I have three controls in the same page

one DetailsView as a summary and two formview

From database i load first data to detailsView with Id as datakey, ApplicationID and ProtocoleID as ordinary attributes for detailsviews, but datakey for each formview.

Once Detailsview loads, I wish automatically from every attribute ApplicationID and ProtocoleID of Detailsview to load both controls since the database.

 

How can i do that ? I think it's only programatically...

All solution is good for me

 

Thanks

 

I would do something like this and put all my addtional controls into an ascx like it is described and pass the data in from your main control.

http://amar.amtechsolutions.com/post/Dynamically-loading-user-controls-with-properties.aspx

Having static controls is better. Declare all the controls statically. in page load, execute three queries and populate the controls appropriately.

Thank's

You know i am new in asp.net.

I am interest by mechanism to

Thank's

[RESOLVED] Just got vs2010, no show data sources in menu for web forms

Hi.

In windows forms, there is the "show data sources" under the "data" menu item, and I love it because I can drag and drop the fields I need onto the form and it makes the control automatically.

In web forms however, this option isn't there.  Why?  I try to drag and drop fields from the "server explorer" but it generates grids, I don't want grids I just want to drag and drop the text boxes or checkboxes etc.

Is there a way to do this with vs 2010?  Thanks.

-JBD

If you want an easy way to pull data in and bind it to display a single record then you should use the FormView control (if you want control over the markup) or DetailsView if you want the table to be generated for you:

Wow thanks, I never used formview before, it should save a ton of time.

No problem.

I like to wire it up using an ObjectDataSource and then plug in my own class to the ObjectDataSource by annotating it with [DataObject(true)] and other attributes. That way the IDE can automatically pick it up and you dont have to manually select each of the select, insert, delete, update statements.

(scroll down about 85% of the way to see a code sample)

Do you happen to know of a way to make the formview and / or dataview  load with the EditItemTemplate?  Or would I have to manually edit every field in itemTemplate?

 

EDIT: Nevermind :)  I set the default mode to edit in the properties derrr :)

[RESOLVED] Multiview and Search Engines

I have a page that uses Multivew and I'm concerned about search engine indexing. In my case, each view is a detailed explanation of features. The user clicks on a hyperlink that changes the active view. They could easily be pages of their own. So I'm wondering how do search engines index multiview pages? The page name doesn't change but the content does. I've even changed the page title and meta description with each view change.

Would I be better to simply make them separate pages instead of separate views?

Guy0510

Would I be better to simply make them separate pages instead of separate views?

I prefer this for better SEO, because that way you can provide Meta description indivisually more specific to that page. it helps search crawls to identify the exact context of the page as page contains only related content. It would be mixed up with other areas.

other side, this method may not give user experience as you expected. Use has to navigate so many pages to view the data. but sometimes I feel if functionality is seperated in multiple pages, it would be clear seperation. It's simple and easy to use.

Based on my understanding, if you want to show a detailed content for one title, you can use DetailsView and GridView. You can set the UpdateCommand properties and update the data to your database.

I think you can click the link located in the GridView and show the detailed information in DetailsView. Then you can set a DataColumn in database stands for the page number and you can operator this value for example insert, update, delate, etc.

Hope this helps,

Esters