Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am new to asp.net, I am preparing a asp project using vb.net code. I want to display the content in gridview in a text box. The gridview is connected with the database.

I tried this by Making the properties of Gridview "Auto Generate Select Button - True" and then I tried the below coding:
C#
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged
       TextBox1.Text = GridView1.SelectedRow.Cells[1].Text
       TextBox2.Text = GridView1.SelectedRow.Cells[2].Text
       TextBox3.Text = GridView1.SelectedRow.Cells[3].Text
       TextBox4.Text = GridView1.SelectedRow.Cells[4].Text
       TextBox5.Text = GridView1.SelectedRow.Cells[5].Text
       TextBox6.Text = GridView1.SelectedRow.Cells[6].Text
   End Sub


In these 6 textboxs, textbox 1, 2, 4, 5 are integers.

In source code I have added:
XML
<asp:GridView ID="GridView1" runat="server" onselectedIndexChanged="GridView1_SelectedIndexChanged" Width="529px"
                style="margin-top: 0px" PageSize="3"
                AllowPaging="True" BorderColor="White" BorderStyle="Ridge"
                SelectedIndex="0" AutoGenerateSelectButton="True">
    </asp:GridView>


But in coding itself I got error that "Value of type
C#
'System.Web.UI.WebControls.TableCellCollection' cannot be converted to 'String'." and "Identifier expected." 

Can you please help me on this?
Posted
Updated 24-Nov-13 22:58pm
v2
Comments
manoj.jsm 26-Nov-13 3:41am    
hi exactly i don't got ur Q but
you may try this
GridView1.SelectedRow.Cells[1].Text.ToString();
this may help you..
Maciej Los 26-Nov-13 13:07pm    
Try this:
TextBox1.Text = GridView1.SelectedRow.Cells(0).Value.ToString()

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