The property "CodigoTreinamento" belongs to my UserControl.
//UserControl
public partial class ExportFormTreinamento : System.Web.UI.UserControl
{
private int _codigoTreinamento { get; set; }
public int CodigoTreinamento
{
get { return _codigoTreinamento; }
set { _codigoTreinamento = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lbtnExportFormulario_Click(object sender, EventArgs e)
{
if (_codigoTreinamento > 0)
{
}
}
}
The method set is working fine but when the User Control is selected the property "CodigoTreinamento" has value 0.
I saw in another forum a question about it (link) and I'm doing almost the same thing. I tried to use "this.DataBind()" in the set method
but it also doesn't work.
Any idea about what to do to fix this problem?
PS.: I'm using Update Panel. Would be it the reason of this problema?
No fim tudo dá certo, se ainda não deu certo é porque ainda não chegou o fim.
I have solved my problem in another way. I added a label in my UserControl and I defined the property "Text" as "TREI_CD_TREINAMENTO", so when the GridView is binding the label gets the value of this column.
Of course it is not the best solution but anyway, it is working now!
Thanks a lot!
No fim tudo dá certo, se ainda não deu certo é porque ainda não chegou o fim.
protected void lbtnExportFormulario_Click(object sender, EventArgs e)
{
if (!CodTraining.Text.Equals(""))
{
//Here, I get the value inside the label
}
}
The DataSource of the GridView has the column "TREI_CD_TREINAMENTO", so the label works as a column of my Grid and I can get its value when I select the UserControl. I also deleted the properties that I was using at the begining.
I hope it can help someone.
No fim tudo dá certo, se ainda não deu certo é porque ainda não chegou o fim.
Deise Vicky
Member
2 Points
9 Posts
Bind User Control inside a GridView
Jan 18, 2013 09:17 AM|LINK
Hi guys;
I'm trying to bind a property of one User Control but it doesn't work. The User Control is inside a GridView.
//Just an example <asp:GridView ID="gvTraining" runat="server" > <Columns> <asp:TemplateField> <ItemTemplate> <uc2:ExportFormTreinamento ID="Export" runat="server" CodigoTreinamento='<%# (int)Eval("TREI_CD_TREINAMENTO") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>The property "CodigoTreinamento" belongs to my UserControl.
//UserControl public partial class ExportFormTreinamento : System.Web.UI.UserControl { private int _codigoTreinamento { get; set; } public int CodigoTreinamento { get { return _codigoTreinamento; } set { _codigoTreinamento = value; } } protected void Page_Load(object sender, EventArgs e) { } protected void lbtnExportFormulario_Click(object sender, EventArgs e) { if (_codigoTreinamento > 0) { } } }The method set is working fine but when the User Control is selected the property "CodigoTreinamento" has value 0.
I saw in another forum a question about it (link) and I'm doing almost the same thing. I tried to use "this.DataBind()" in the set method but it also doesn't work.
Any idea about what to do to fix this problem?
PS.: I'm using Update Panel. Would be it the reason of this problema?
geniusvishal
All-Star
15163 Points
2953 Posts
Re: Bind User Control inside a GridView
Jan 18, 2013 11:20 AM|LINK
Refer these links:
http://forums.asp.net/t/1167638.aspx
http://aspdotnetcodebook.blogspot.in/2008/04/how-to-load-web-user-control-inside.html
My Website
www.dotnetvishal.com
Deise Vicky
Member
2 Points
9 Posts
Re: Bind User Control inside a GridView
Jan 18, 2013 11:40 AM|LINK
Thank you for your answer.
I have solved my problem in another way. I added a label in my UserControl and I defined the property "Text" as "TREI_CD_TREINAMENTO", so when the GridView is binding the label gets the value of this column.
Of course it is not the best solution but anyway, it is working now!
Thanks a lot!
geniusvishal
All-Star
15163 Points
2953 Posts
Re: Bind User Control inside a GridView
Jan 18, 2013 11:43 AM|LINK
Welcome.. If Possible Please Share Your Solution so that it might benefit the community..
Thank You.
My Website
www.dotnetvishal.com
Deise Vicky
Member
2 Points
9 Posts
Re: Bind User Control inside a GridView
Jan 18, 2013 11:52 AM|LINK
Yes, of course!
User Control:
<asp:LinkButton ID="lbtnExportFormulario" runat="server" Enabled="true" CssClass="ToolbarButton" onclick="lbtnExportFormulario_Click" > <img style="border-width: 0px;" src="../App_Themes/NetNews/Images/ExportPdf.gif" id="ImgExp" /> <asp:Label ID="CodTraining" runat="server" Visible="false" Text='<%# Eval("TREI_CD_TREINAMENTO")%>' /> </asp:LinkButton>protected void lbtnExportFormulario_Click(object sender, EventArgs e) { if (!CodTraining.Text.Equals("")) { //Here, I get the value inside the label } }GridView in a WebForm:
<asp:GridView ID="gvTraining" runat="server" <Columns> <asp:TemplateField ItemStyle-Width="1%" ItemStyle-Wrap="false"> <ItemTemplate> <uc2:ExportFormTreinamento ID="ExportFormTreinamento1" runat="server" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>The DataSource of the GridView has the column "TREI_CD_TREINAMENTO", so the label works as a column of my Grid and I can get its value when I select the UserControl. I also deleted the properties that I was using at the begining.
I hope it can help someone.