getting textbox value

Posted by Vikas1248 under ASP.NET on 8/19/2012 | Points: 10 | Views : 678 | Status : [Member] | Replies : 1
how to get textbox items when selecting a rowin gridview manually using templatefield.(without datasource or objectsource)




Responses

Posted by: Vikash on: 8/19/2012 [Member] Starter | Points: 25

Up
0
Down
your .aspx file

<asp:TemplateField HeaderText="Hr Name" >
<ItemTemplate >
<asp:TextBox ID ="lbl2" runat ="server" Text ='<%#bind("Hr_Name") %>' />
</ItemTemplate>
</asp:TemplateField>

your code-behind file

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
MessageLabel.Text = String.Format("You selected row {0} with {1}",
GridView1.SelectedIndex + 1,
((TextBox)GridView1.SelectedRow.FindControl("lbl2")).Text);
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//add css to GridViewrow based on rowState
e.Row.CssClass = e.Row.RowState.ToString();
//Add onclick attribute to select row.
e.Row.Attributes.Add("onclick", String.Format("javascript:__doPostBack('GridView1','Select${0}')", e.Row.RowIndex));
}
}

Regards,
Vikash Pathak

Vikas1248, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response