Click here to Skip to main content
16,012,166 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.

For eg:

If I have 4 columns in gridview , and I have 4 textboxes. Then If I click on the 1st row then the content in the 4 columns must be displayed in 4 textboxes.

I know vb.net a little but poor in asp.

Please help me.
Posted

 
Share this answer
 
Comments
Member 10419145 25-Nov-13 5:49am    
Hi,

I tried this by Making the properties of Gridview "Auto Generate Select Button - True" and then I tried the below coding:

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:

<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">

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

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

to

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

And I got the answer
 
Share this answer
 

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