M
moni
Hi,
I was hoping to know how I could get the text value of a gridview row.
My code is this way:
<asp:GridView ID="GridView1" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
BackColor="#8080FF"
BorderColor="#0000C0" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2" Font-
Size="Large" Height="192px" Width="243px"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:ButtonField DataTextField="Name" HeaderText
="Select" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="DarkBlue" Font-Bold="True"
ForeColor="White" />
</asp:GridView>
//To bind data
SqlConnection conn = new SqlConnection(connString);
conn.Open();
String sqlstr = null;
sqlstr = "Select Name,Address,ZipCode from restaurants
where ZipCode='" + TextBox1.Text + "'";
/*
//get values of the gridview items displayed as
addresses
//call the javascript function for adding each point
as an overlay
*/
SqlCommand comm = new SqlCommand(sqlstr, conn);
GridView1.DataSource =
comm.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataBind();
GridView1.Focus();
conn.Close();
This is being able to bind and display data properly. But on a row
select, it is displaying the correct index , but not the text.
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
Label4.Text = GridView1.SelectedRow.RowIndex.ToString();
}
Even
GridView1.SelectedRow.Cells[0].Text;
gives me a blank label.
Any help will be appreciated. Thanks
I was hoping to know how I could get the text value of a gridview row.
My code is this way:
<asp:GridView ID="GridView1" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
BackColor="#8080FF"
BorderColor="#0000C0" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2" Font-
Size="Large" Height="192px" Width="243px"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:ButtonField DataTextField="Name" HeaderText
="Select" />
</Columns>
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="DarkBlue" Font-Bold="True"
ForeColor="White" />
</asp:GridView>
//To bind data
SqlConnection conn = new SqlConnection(connString);
conn.Open();
String sqlstr = null;
sqlstr = "Select Name,Address,ZipCode from restaurants
where ZipCode='" + TextBox1.Text + "'";
/*
//get values of the gridview items displayed as
addresses
//call the javascript function for adding each point
as an overlay
*/
SqlCommand comm = new SqlCommand(sqlstr, conn);
GridView1.DataSource =
comm.ExecuteReader(CommandBehavior.CloseConnection);
GridView1.DataBind();
GridView1.Focus();
conn.Close();
This is being able to bind and display data properly. But on a row
select, it is displaying the correct index , but not the text.
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
Label4.Text = GridView1.SelectedRow.RowIndex.ToString();
}
Even
GridView1.SelectedRow.Cells[0].Text;
gives me a blank label.
Any help will be appreciated. Thanks