Private Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow = GridView1.SelectedRow '' give you the selected row
Dim value As String = row.Cells(0).Text.ToString() '' give you the cell no 0 ,, change this if you value is not in cell 0
Dim arr() As String = value.Split(" ") 'split it (here i split it by space
TextBox1.Text = arr(0).ToString() ' asign value
TextBox2.Text = arr(1).ToString() 'asign value
End Sub
Please "Mark as Answer" if this post helps.Thank You :)
Das_Ramani
Member
4 Points
36 Posts
How split gridview column value and show in two text box
May 02, 2012 03:41 AM|LINK
How split gridview column value and show in two text box on selectindexchange event in gridview in asp.net
I have two textbox bind that value to gridview one column then I want that value split and show in two text box on gridview_selectindexchanged
chiragtoad
Member
212 Points
51 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 05:27 AM|LINK
check this link this may help you out
http://stackoverflow.com/questions/6095504/how-can-i-get-selected-row-cell-value-of-grid-view-on-page
rio.jones
Member
246 Points
53 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 05:31 AM|LINK
Hello,
Hello you can use dplit function of .net to split the values. Please post some of your code so taht we can help you better.
tusharrs
Contributor
3230 Points
668 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 05:43 AM|LINK
here assing gridview column value to string str for example i have taken "abc 123" for separating it with space
string str = "abc 123";
string[] arrstr = str.ToString().Split(' ');
if (arrstr.Length>0)
{
txt1.Text = arrstr[0].ToString();
}
if (arrstr.Length > 1)
{
txt1.Text = arrstr[1].ToString();
}
now your textbox txt1 will contain "abc" and textbox txt2 will contain "123"
( Mark as Answer if it helps you out )
View my Blog
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 06:26 AM|LINK
hi try this
Private Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged Dim row As GridViewRow = GridView1.SelectedRow '' give you the selected row Dim value As String = row.Cells(0).Text.ToString() '' give you the cell no 0 ,, change this if you value is not in cell 0 Dim arr() As String = value.Split(" ") 'split it (here i split it by space TextBox1.Text = arr(0).ToString() ' asign value TextBox2.Text = arr(1).ToString() 'asign value End SubDas_Ramani
Member
4 Points
36 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 08:31 AM|LINK
I try ur code but error is comming
Index was outside the bounds of the array.
asp.netC#
Das_Ramani
Member
4 Points
36 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 08:39 AM|LINK
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
string[] data = row.Cells[2].Text.ToString().Split(',');
if (data.Length > 0)
{
TextBox3.Text = data[0].ToString();
}
if (data.Length > 1)
{
TextBox4.Text = data[1].ToString();
}
}
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 08:45 AM|LINK
which code have you tried?
and if you haven't tried my code yet try it
and tell me where exactly is the error
tusharrs
Contributor
3230 Points
668 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 08:51 AM|LINK
check how many columns you have in gridview
string[] data = row.Cells[2].Text.ToString().Split(',');
this means you must have 3rd column in the gridview
put a breakpoint and see what value you get in data array
and
if (data.Length > 0)
{
TextBox3.Text = data[0].ToString();
}
if (data.Length > 1)
{
TextBox4.Text = data[1].ToString();
}
is perfectly running at my end
( Mark as Answer if it helps you out )
View my Blog
Das_Ramani
Member
4 Points
36 Posts
Re: How split gridview column value and show in two text box
May 02, 2012 09:43 AM|LINK
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
string[] data = row.Cells[2].Text.ToString().Split(',');
TextBox3.Text = data[0].ToString();
TextBox4.Text = data[1].ToString();
}
This is my code
after debug error is cooming
Index was outside the bounds of the array.