I am having one web application...

On which i have one combobox whose autopostback propert is set to true....
its showing d same result that i want...
the only problem is that the page gets refreshed automatically when i select a data from combobox....

How to overcome this problem pls help me out.....

if you have set the autopostback to true it will refresh the page or make a postback.

The other way is you can wrap that combo in to update panel. use ajax

Check your page load event. Your combobox may be bound to some data source which is making your combobox get refreshed with new values every time page gets refreshed .

You can use IsPostBack = False
and bound the data on change event of Combo box instead of page load event.

I hope this helps.

No its not working


Here is code:

Default.aspx Design:
Contain dropdown box,textbox,button


Default.aspx Source code:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
            DataTextField="UserId" DataValueField="UserId" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MOVIETICKETBOOKING.MDFConnectionString %>"
            SelectCommand="SELECT * FROM [UserInfo]"></asp:SqlDataSource>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
    </form>
</body>
</html>

Default.aspx.cs:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
       protected void Button1_Click(object sender, EventArgs e)
    {
TextBox1.Text = DropDownList1.Text;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.