Reputation: 99
<asp:HiddenField ID="hidapplyuid" runat="server" EnableViewState="true" />
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="UID" CssClass="" runat="server" Text='<%#Eval("candUID")%>'></asp:Label>
<asp:Label ID="JobApplyUID" CssClass="" runat ="server" Text='<%#Eval("jobApplyUID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
need to bind the JobApplyUID to the hiddenfield in cs page... please help me...
Upvotes: 1
Views: 11671
Reputation: 349
Assessing controls from gridview is very easy try this demo as follows. Add new test page in your project. Lets have ASPX page as shown below...
<div>
Job Apply GUID : <asp:Label runat="server" ID="uxJobApplyUID"></asp:Label>
<asp:GridView ID="uxGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="JobApply UID">
<ItemTemplate>
<asp:HiddenField ID="uxHiddenJobApplyUID" runat="server" Value='<%#Eval("jobApplyUID") %>' />
<asp:Button ID="uxShowDetails" runat="server" Text="Show Data" OnClick="uxShowDetails_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
And code behind will be as follows...
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("jobApplyUID", typeof(string));
dt.Rows.Add(System.Guid.NewGuid().ToString());
dt.Rows.Add(System.Guid.NewGuid().ToString());
dt.Rows.Add(System.Guid.NewGuid().ToString());
dt.Rows.Add(System.Guid.NewGuid().ToString());
dt.Rows.Add(System.Guid.NewGuid().ToString());
uxGrid.DataSource = dt;
uxGrid.DataBind();
}
}
protected void uxShowDetails_Click(object sender, EventArgs e)
{
this.uxJobApplyUID.Text = (((sender as Button).NamingContainer as GridViewRow).FindControl("uxHiddenJobApplyUID") as HiddenField).Value;
}
If you try this you can get value from any control present in gridview.
Upvotes: 0
Reputation: 16245
You need to put the HiddenField
inside of a TemplateField
, else it won't be databound since the GridView
, DetailsView
, etc cannot access it
Change from this
<asp:HiddenField ID="hidapplyuid" runat="server" EnableViewState="true" />
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="UID" CssClass="" runat="server" Text='<%#Eval("candUID")%>'></asp:Label>
<asp:Label ID="JobApplyUID" CssClass="" runat ="server" Text='<%#Eval("jobApplyUID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
To something like this. Move it to a TemplateField
someplace, for example
<asp:TemplateField>
<ItemTemplate>
<%-- Move hidden variable inside of the template, else it cannot be databound --%>
<asp:HiddenField ID="hidapplyuid" runat="server" Value='<%#Eval("jobApplyUID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Label ID="UID" CssClass="" runat="server" Text='<%#Eval("candUID")%>'></asp:Label>
<asp:Label ID="JobApplyUID" CssClass="" runat ="server" Text='<%#Eval("jobApplyUID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1