Click here to Skip to main content
16,012,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
Is there any control to fill the data from database and perform postback operation.
I want to fill a field from my database and after selecting that the selected field should be displayed in the textbox.
Posted
Updated 27-Sep-11 15:00pm
v3

1 solution

Hi,

you can use any data control from basic asp.net controls

you can see list of data controls in toolbox like..datalist,reapeter,gridview...


And write code to display data in selectedindexchanged event


http://msdn.microsoft.com/en-us/library/cc295567.aspx

In the above link you can see details about data controls

ASP.NET
<form id="form1" runat="server">
<div>
<br />
    <asp:TextBox ID="TextBox1" runat="server"><br />
    <asp:DataList ID="DataList1" runat="server" onitemcommand="DataList1_ItemCommand" Width ="60%"
       >
     <HeaderTemplate >
       <table width="100%" align="center">
         <tr>
           <td>List of Items</td>
         </tr>

     </HeaderTemplate>
     <itemtemplate>
          <tr>
           <td>
               <asp:LinkButton ID="LinkButton1" runat="server" CommandName ="show" CommandArgument ="3"> <asp:Label ID="Label1" runat="server" Text=' <%#Container.DataItem %>'>

           </td>
         </tr>
     </itemtemplate>
     <footertemplate>
         </footertemplate></table>



</div>
</form>


And code behind file contains following code

C#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

   
            List<string> str = new List<string>();
            str.Add("frstitem");
            str.Add("secnditem");
            str.Add("ghgfh");
            str.Add("frstitem");
            str.Add("secnditem");
            str.Add("ghgfh");
            str.Add("frstitem");
            str.Add("secnditem");
            str.Add("ghgfh");

            DataList1.DataSource = str;
            DataList1.DataBind();
         

        }
    }

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "show")
        {
            Label lbl = (Label)e.Item.FindControl("Label1");
            TextBox1.Text = lbl.Text;
        }
    }
</string></string>


In the above example we can set database to datalist as per older method


All the Best
 
Share this answer
 
v2
Comments
kwhiterosek 27-Sep-11 9:23am    
fine.can u tell me the code to display the textbox with selected item. if i place a code in selectedindexchanged event as like 'TextBox1.Text = ListBox1.SelectedItem.Text' it works at first time then shows error at the next time. what to do?
Muralikrishna8811 27-Sep-11 9:24am    
k I can post with code
kwhiterosek 27-Sep-11 9:41am    
Murali,
No need for coding in selectedindexchanged event?
Muralikrishna8811 27-Sep-11 9:43am    
is above code wrking for you?

you can write in item command event.

itemcommand event raises when you click on datalist.so that means we can handle

selection change event also
kwhiterosek 27-Sep-11 9:48am    
i ll try that now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900