hi ,,i m using asp.net 2005 in VB language and sqlserver 2005,,so here i m with a new problem......i have a textbox and a button in my form,,,i m using a table called as details..i want the fname from details table to be displayed in the textbox and on the click of the button the next fname should be displayed in the text box....ok first things first,,i can bind the fname to a dropdown list,,but how can i bind it to a text box...
waiting for ur reply guys,,thnks in advance:(

hi ,,i m using asp.net 2005 in VB language and sqlserver 2005,,so here i m with a new problem......i have a textbox and a button in my form,,,i m using a table called as details..i want the fname from details table to be displayed in the textbox and on the click of the button the next fname should be displayed in the text box....ok first things first,,i can bind the fname to a dropdown list,,but how can i bind it to a text box...
waiting for ur reply guys,,thnks in advance:(

well guys i think i hav found the way for my 1st problem,,this code is workin fine for me
here is the code

Dim st2 As String = ConfigurationManager.ConnectionStrings("jayConnectionString").ConnectionString
    Dim conn As New SqlConnection(st2)
Dim cmd = New SqlCommand("select caddress from details", conn)
        conn.Open()
        TextBox1.Text = Convert.ToString(cmd.ExecuteScalar())

the textbox gives the first value of fname in the table...now wht i want is on the click of the button ,the textbox should display the 2nd fname from the table and so onn,,,how cani achieve tht,,,need ur help guys....pls reply asap,,
thnks in advance

common guys i need help,,,,,,waiting for ur reply

you can make a variable
dim i as int32 = 0
for each click (button)
i +=1
and make the i is the index of rows in the data base
don't forget to handle the last row of the data base

you can take the resulr in a reader then populate the reader contents in arraylist. then populate the values form arraylist. i have coded it in C#

SqlCommand m_Command=new SqlCommand(CommandText,m_Connection);
        m_Connection.Open();
        SqlDataReader Reader = m_Command.ExecuteReader();
            while(Reader.Read()){
                int j=0;
                object[]values=new object[Reader.FieldCount];
                
                Reader.GetValues(values);
                rowList.Add(values[i]);
                j++;
            }
            Reader.Close();

on button click you can populate the textbox

txtname.Text = rowList[i].ToString();
        i++;//declare i as static n check for arraylimit

hi,

try like this

<table>
<tr>
<td>
<asp:TextBox ID="txtid" runat="server"></asp:TextBox>
</td>

</tr>
<tr>
<td>
<asp:Button ID="btnsubmit" runat="server"  Text="Submit" OnClick="btnsubmit_Click"/>
</td>
</tr>
</table>


in code behind:

static string[] strname;
    static int count=1;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            BindGrid();
        }
    }


    private void BindGrid()
    {

        SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False ");
        
        SqlDataAdapter da = new SqlDataAdapter("", conn);
        da.SelectCommand = new SqlCommand("select CategoryName from Categories", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "data");
        if(ds.Tables[0].Rows.Count>0)
         {
             strname = new string[ds.Tables[0].Rows.Count];
                 for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                    {
                       strname[i] = ds.Tables[0].Rows[i].ItemArray[0].ToString();
                    }
                    txtid.Text = strname[0].ToString();
         }
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {

        if (count < strname.Length)
        {
            txtid.Text = strname[count].ToString();

            count = count + 1;
        }

    }

Hi,

The only thing you need to do is get the next fname from database and set its value to textbox, Now you can solve this problem with more then one way. one of the way can be:
you get fname list first time from database and store list in session/viewstate etc and maintain counter between postbacks using session/viewstate and every time show next item from list and increase counter.

you can make call to database every time and maintain counter using primary key etc..

logic is to maintain counter of next item in between postbacks.

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.