Problem with GridView: How to change the text of Button in a GridView Cell ?
-
How can I show additional button in a gridview cell based on another cell value.I am using asp.net and c#. I have ON or OFF values in a GridView cell. Based on this value I want to show a button (opposite Toggle (OFF/On) correspondingly) in another cell. This is my code. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.Cells[2].Text== "0") e.Row.Cells[2].Text = "OFF"; else e.Row.Cells[2].Text = "ON"; } please help. Thank You
-
How can I show additional button in a gridview cell based on another cell value.I am using asp.net and c#. I have ON or OFF values in a GridView cell. Based on this value I want to show a button (opposite Toggle (OFF/On) correspondingly) in another cell. This is my code. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.Cells[2].Text== "0") e.Row.Cells[2].Text = "OFF"; else e.Row.Cells[2].Text = "ON"; } please help. Thank You
Are you looking for UnBound TemplateField ? Simply add
" CommandName="ToggleClick"
CommandArgument='<%#Eval("Toggle") %>/>
and use
OnRowCommand
to handle this event. :)Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Are you looking for UnBound TemplateField ? Simply add
" CommandName="ToggleClick"
CommandArgument='<%#Eval("Toggle") %>/>
and use
OnRowCommand
to handle this event. :)Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>thanks for the reply, but there is something wrong with this code. Can u recheck it plz? Thank You
-
thanks for the reply, but there is something wrong with this code. Can u recheck it plz? Thank You
Yes.. Actually I have written this directly.. Not tried out.... Can you let me know what error you are getting ... ? Well,
Eval("field")
should be changed with your valid database field ?? Also change the fieldnames according to the datasource you bound to.Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Yes.. Actually I have written this directly.. Not tried out.... Can you let me know what error you are getting ... ? Well,
Eval("field")
should be changed with your valid database field ?? Also change the fieldnames according to the datasource you bound to.Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>Actually I am using it as a TemplateField. It's value is not coming from database. what can be the solution? Thank You.
-
Actually I am using it as a TemplateField. It's value is not coming from database. what can be the solution? Thank You.
Then Just place True / false instead of Eval statement.. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Then Just place True / false instead of Eval statement.. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>I have written this. theres is some problem. It shows "Convert.ToBoolean(true)". What is the problem? <asp:TemplateField HeaderText="Mode"> <ItemTemplate> <asp:Button runat="server" Text="<%!Convert.ToBoolean(true) %>" CommandName="ToggleClick" CommandArgument=<%#true %>/> </ItemTemplate> </asp:TemplateField> Thank You
-
I have written this. theres is some problem. It shows "Convert.ToBoolean(true)". What is the problem? <asp:TemplateField HeaderText="Mode"> <ItemTemplate> <asp:Button runat="server" Text="<%!Convert.ToBoolean(true) %>" CommandName="ToggleClick" CommandArgument=<%#true %>/> </ItemTemplate> </asp:TemplateField> Thank You
No no.. write this...
<asp:TemplateField HeaderText="Mode">
<ItemTemplate>
<asp:Button runat="server" Text="True" CommandName="ToggleClick" CommandArgument="True" />
</ItemTemplate>
</asp:TemplateField>In
CommandArgument
you need to specify what you want to pass to the event generated when button is clicked. I have placed true there, which is not required. Replace appropriate element there (I mean the field which might be dependent on the button) :)Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>