I am trying to create a column in a GridView that contains a button and can be clicked on to select the row. When I try to assign an ImageURL (that exists) to the button, it does not display and seems as if the link is broken. Here's the code I am using:
<asp:ButtonField HeaderText="Select" ButtonType="Image" CommandName="Select" ImageUrl="../Images/SemiWorksPLM/unchecked.png"/>
However I can create an Image inside a TemplateField using the same URL and it appears okay:
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:Image ID="Image1" ImageUrl="../Images/SemiWorksPLM/unchecked.png" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Any idea why it would work for the Image in the TemplateField but not the ButtonField?
you could try doing it the next way:
1 - Change ButtonType to to link
2 - put the image in the text area
<asp:ButtonField CommandName="Preview" Text="<img src='Images/SemiWorksPLM/unchecked.png' style='border-width:0' />" ButtonType="Link" />
Try using a url relative the the root directory of the website:
ImageUrl="~/Images/Image2.bmp"
Related
I am now developing windows application using c#.net.
now i want to add four image buttons in datagridview cell like following picture.
Is it possible to do it? is there any control to do as the following picture.
Best Rgds,
DF
You need to add a template field as a column in your grid view. Then in the item template you can put asp image buttons. For example:
<asp:GridView runat="server" id="gdv_gridviewname" >
<Columns>
<asp:TemplateField HeaderText="Image Buttons">
<ItemTemplate>
<asp:ImageButton runat="server" ID="imgBtnSomething" ImageURL="Path to your image" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am inserting record in datagrid by binding it with data table and I had set autogenerate field ON for datagrid. Now all I want is first column which will comes in datagrid should be hyperlink field and when I will click on link it should redirect to another page. Please help
do like :
<ItemTemplate>
<asp:HyperLink ID="Edit" runat="server" Text="Edit" NavigateUrl='<%# Eval("DataKeyName", "~/View.aspx?Id={0}") %>' />
</ItemTemplate>
Edit:
You need to change the column type to a Hyperlink column.
and where to set is your job Sandesh
<Columns>
<asp:hyperlinkfield headertext="NewsHeadline"
datatextfield="NewsHeadline"
datanavigateurlfield="NewsURL"
datanavigateurlformatstring="http://{0}" />
</Columns>
I am importing a column in datatable to my grid. Now I want navigate to a new page on selecting a cell in grid by fetching the selected value. I have tried this by including bound field in my grid like
<asp:GridView ID="GDV_1" runat="server" EnableModelValidation="true" AutoGenerateColumns="false" OnSelectedIndexChanged="GDV_1_SelectedIndexChanged" AutoGenerateSelectButton="false" DataKeyNames="SROID">
<Columns>
<asp:BoundField DataField="SRONameinEnglish" HtmlEncode="False" DataFormatString="<a target='_blank' href='Test.aspx?code={0}>ClickHere</a>" />
</Columns>
</asp:GridView>
Doing this way my requirement is achieved but the all cells are displaying Common text Click here instead of showing data from Database.
Please give your suggestion on how to get the value from database into cell and make it clickable. I don't want to use Select button. Please find my current output.
This is my current output I want my data from DB instead of ClickHere.
You can use TemplateField
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnk<%# Eval("SRONameinEnglish")%>"><%# Eval("SRONameinEnglish")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
and click of LinkButton put your code to navigate anywhere.
In your case you are binding boundfield with static a tag which have href attribute so your not able to change text on that boundfield from your database.To get your approach you should
use TemplateField and bind data with text attribute using eval keyword as below example.
Try it:
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("name") %>' />
</ItemTemplate>
</asp:TemplateField>
OR
you can also bind link with your hyperlink using NavigateUrl property of hyperlink as below example.
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink id="HyperLink2" NavigateUrl='<%#Eval("YourUrl") %>' Text='<%#Eval("name") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
I hope it will helpful to you.
In ASP.NET 2.0 web application, there is a gridview and user wanted to change the font size of contents of that grid view. Below is Gridview definition and server side code to set the font-size of contents of gridview. Everything is fine except, textboxes in bounded fields of gridview. The font size does not applied on them.
GridView :
<asp:TemplateField HeaderText="Display Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="100px" Text='<%# Bind("DisplayName") %>' OnTextChanged="TextBox_TextChanged" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("DisplayName") %>' />
</ItemTemplate>
</asp:TemplateField>
ServerSide Code:
ObjPListSetting.Style["font-size"] = sTextSize + "px";
where, sTextSize is target value (i.e. 12, 14, 16).
Why is that so? Anyone can help in this regard.
In the OnRowDataBound event hander do something like this.
TextBox txtTextBox1 = RowObject.FindControl("TextBox1");
txtTextBox1.Style["font-size"] = sTextSize + "px";
This is a dummy code. Just check how you get the rowobject in below link.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
I want to add a link button in grid view that will navigate to the next form in the website. but i want to know how to insert that button into the grid view column? please help me..
You can add Link buttons in the Item template of a gridview.
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Link" runat="server" PostBackUrl="MyNextPage.aspx">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
// TEXT FOR COLUMN NAME
</HeaderTemplate>
<ItemTemplate>
// ADD LINK BUTTON HERE.
</ItemTemplate>
</asp:TemplateField>
</Columns>
Add this inside grid view.
try this
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:ButtonField ButtonType="Link" HeaderText="LinkButton"/>
</Columns>
</asp:GridView>
Make Sure your GridViews datasource is bound. Set Auto-Generate Columns to false.
Open GridViewTask , add new column with Hyperlink Field proper name and path . You are done.