I have 2 buttons in a column of my GridView control.
<asp:TemplateField ItemStyle-CssClass="minPadding">
<ItemTemplate>
<input id="btnDateRange" type="button" value="Date Range" class="JQDatePicker SmallText FloatRight WrapButtonText" onclick="javascript:document.getElementById('hdnImpressionTagID').value = '<%# Eval("ImpressionTagID") %>'"/>
<asp:Button ID="btnShowImpressions" CommandArgument='<%# Eval("ImpressionTagID") %>' CommandName="ShowImpressions" Text="Total Impressions" runat="server" UseSubmitBehavior="false" CssClass="SmallText FloatLeft WrapButtonText" Width="80px" />
</ItemTemplate>
</asp:TemplateField>
The reason the first button is an HTML control is because when I try to use an asp:button - the onclick event doesn't work (note the #Eval statement inside the javascript call) Using a server control gives me the error : 'Server tag is not well formed'
I want to change the text of these buttons from my code behind. (I'm using c#)
I find the correct row index and I know they are in cell 5.
I can set the asp:Button control's text like so...
Button btn = ((Button)gridImpressionTags.Rows[i].Cells[5].FindControl("btnDateRange"));
btn.Text = "This Text has changed!";
The problem is: The Web control btnDateRange
appears as a DataBoundLiteralControl
when referenced from code behind & I am unable to cast it as a button.
I am also unable to cast it as a literal. Unable to cast object of type 'System.Web.UI.DataBoundLiteralControl' to type 'System.Web.UI.WebControls.Literal'.
And casting it as a DataBoundLiteralControl works, but then doesn't allow me to change the text: System.Web.UI.DataBoundLiteralControl.Text' cannot be assigned to -- it is read only
Does anyone know why my HTML button is being rendered as a DataBoundLiteralControl ? Does anyone have any ideas for me to try for me at all ?
Any suggestions are appreciated!