I have this ASPX code:
<asp:GridView ID="GV_" runat="server">
<Columns>
<asp:TemplateField HeaderText="Eliminar">
<ItemTemplate>
<asp:Button ID="Eliminar_BTN__" runat="server" Text="" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Editar">
<ItemTemplate>
<asp:Button ID="Editar_BTN__" runat="server" Text="" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WI">
<ItemTemplate>
<asp:DropDownList ID="WI_DDL__" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ITEM">
<ItemTemplate>
<asp:DropDownList ID="ITEM_DDL__" runat="server"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="L" />
<asp:BoundField HeaderText="M" />
<asp:BoundField HeaderText="X" />
<asp:BoundField HeaderText="J" />
<asp:BoundField HeaderText="V" />
<asp:BoundField HeaderText="S" />
<asp:BoundField HeaderText="D" />
</Columns>
</asp:GridView>
What I want to do is to have a button that when I click on it, I add a row to this gridview, the problem is that the gridview has 2 templatefield columns and I don't know how to do it.
Can someone throw some light on this?
Thanks!
Rick is correct; you need to add to the data source. This is a similar example - Dropdownlist in Gridview value
Related
For each row in GridView i have a HyperLink, and i need to generate different ID´s for each of them. Using Eval doesn´t work properly:
<asp:GridView
ID="ResultTableGvw"
runat="server"
AutoGenerateColumns="false"
OnRowDataBound="ResultTableGvw_RowDataBound">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="ID" DataField="id" />
<asp:BoundField ReadOnly="true" HeaderText="accountId" DataField="externalId" />
<asp:BoundField ReadOnly="true" HeaderText="tydeId" DataField="typeId" />
<asp:BoundField ReadOnly="true" HeaderText="Estado" DataField="statusId" />
<asp:BoundField ReadOnly="true" HeaderText="Timestamp do Pedido" DataField="timestampRequest" />
<asp:TemplateField HeaderText="Operação" ItemStyle-Wrap="false">
<ItemTemplate>
<asp:HyperLink
ID='<%# DataBinder.Eval( Container.DataItem, "Id", "OperationManagementHl{0}") %>'
runat="server"
Text="">
</asp:HyperLink>
</ItemTemplate>
<ItemStyle Wrap="False"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
Any suggestion to solve this problem?
The error is : The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:Button runat="server" id="Button1" />
Try with this pattern and it works for me,
<asp:Label ID="lblNames" runat="server" Text='<%# Eval("Names") %>' Height ="60px" Width ="90%" CssClass="LabelDesign" />
I have a gridview:
<asp:GridView ID="ParentSelect" runat="server" AutoGenerateColumns="false" OnRowCommand="ParentSelect_RowCommand" OnRowCreated="ParentSelect_RowCreated" emptydatatext="Please Submit A Clip. C'mon dude." ShowHeaderWhenEmpty="true" HorizontalAlign="Center" Width="600" CssClass= "table table-striped table-bordered table-condense" OnDataBound="ParentSelect_DataBound" DataKeyNames="SubmissionID" RowStyle-Wrap="true">
<HeaderStyle BorderColor="Black" />
<Columns>
<asp:BoundField DataField ="SubmissionID" />
<asp:TemplateField HeaderText ="Vote" ItemStyle-HorizontalAlign="center" HeaderStyle-CssClass="DisplayCenterHeaderGrid">
<ItemTemplate>
<asp:Imagebutton ID="VoteUp" runat="server" ImageUrl="Content/glyphicons-202-upload.png" Width="20" ToolTip="Vote Up" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>
" CommandName="VoteUp" OnCommand="VoteUp_Command" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField ="Title" HeaderText="Title" Visible="True" HeaderStyle-Width="30" HeaderStyle-CssClass="DisplayCenterHeaderGrid"/>
<asp:BoundField DataField ="VideoUrl" HeaderText="Title" Visible="false" />
<asp:BoundField DataField ="Description" HeaderText="Title" Visible="false" />
<asp:BoundField DataField ="GenreSelection" HeaderText="Genre" Visible="True" HeaderStyle-Width="30" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-CssClass="DisplayCenterHeaderGrid" />
</Columns>
</asp:GridView>
I have tried virtually every way imaginable to set specific column widths and have been unsuccessful in doing so. Please help
Try to set ItemStyle-Width this property for your BoundField
<asp:BoundField DataField ="Title" HeaderText="Title" Visible="True"
HeaderStyle-Width="30" HeaderStyle-CssClass="DisplayCenterHeaderGrid"
ItemStyle-Width="300px"/>
In design view, click the GridView handle. Convert the BoundField to a TemplateField. Edit the template. Set the width property of the control in the ItemTemplate.
resulting sample code:
<asp:TemplateField HeaderText="Comments" SortExpression="comments">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("comments") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("comments") %>' Width="400px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I have 8 columns populated as checkboxes in a gridview. I need to know how to get the values from them and store them in a database using C#. Kindly help.
aspx code:
<asp:GridView ID="GridView1" runat="server" CssClass="etable" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="rollnumber" HeaderText="Roll Number" />
<asp:BoundField DataField="name" HeaderText="Name" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="IBM">
<ItemTemplate>
<asp:CheckBox ID="chkibm" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="FOL">
<ItemTemplate>
<asp:CheckBox ID="chkfol" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="IS">
<ItemTemplate>
<asp:CheckBox ID="chkis" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="CP">
<ItemTemplate>
<asp:CheckBox ID="chkcp" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="WIM">
<ItemTemplate>
<asp:CheckBox ID="chkwim" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="STTPO">
<ItemTemplate>
<asp:CheckBox ID="chksttpo" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="TDM">
<ItemTemplate>
<asp:CheckBox ID="chktdm" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="PA">
<ItemTemplate>
<asp:CheckBox ID="chkpa" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="ID Card">
<ItemTemplate>
<asp:CheckBox ID="chkid" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
If the CheckBox Field is in database use this
<asp:CheckBoxField DataField="IBM" HeaderText="IBM"/>
instead of
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="IBM">
<ItemTemplate>
<asp:CheckBox ID="chkibm" runat="server" />
</ItemTemplate>
</asp:TemplateField>
I have the following GridView:
<asp:GridView ID="gvDispMsg" ClientIDMode="Static" ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" EmptyDataText="There is no data to display" runat="server" AllowPaging="false" AllowSorting="true">
<Columns>
<asp:BoundField HeaderText="Delete Message" HeaderStyle-Width="12%" />
<asp:BoundField HeaderText="ID" HeaderStyle-Width="12%" DataField="ID" />
<asp:BoundField HeaderText="Date" HeaderStyle-Width="13%" DataField="Created" />
<asp:BoundField HeaderText="Message" HeaderStyle-Width="45%" DataField="Message" />
<asp:BoundField HeaderText="Active" HeaderStyle-Width="10%" DataField="Active" />
<asp:BoundField HeaderText="Created By" HeaderStyle-Width="20%" DataField="CreatedBy" />
</Columns>
</asp:GridView>
It is populated from a SQL table which is executed from code-behind. The only column which is not populated is the Delete Message column.
How can I add a button for each row in the Delete Message column which takes the argument for the ID datafield?
Add
<asp:GridView AutoGenerateDeleteButton="true" DataKeyNames="ID" OnRowDeleted="NewEvent"
and handle the NewEvent in CodeBehind
or
add a <asp:ButtonField ButtonType="Button" CommandName="delete" Text="Delete" HeaderText="Delete"/> instead of a BoundField
or
add
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="lbiDelete" runat="server" CommandName="Delete" CommandArgument='<%# Bind("ID") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="lbiDelete" runat="server" CommandName="Delete" CommandArgument='<%# Bind("ID") %>' />
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="lbiDelete" runat="server" CommandName="Delete" CommandArgument='<%# Bind("ID") %>' />
</FooterTemplate>
</asp:TemplateField>
where you have most abilities to configure this column in every state
I have a gridview control and I would like the field Title to be a hyperlink and execute a stored procedure when clicked. Can anyone assist me in this?
Does this code look right?
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hpTitle" runat="server" Text='<%# Bind("Title") %>' NavigateUrl='<%# Bind("SelectBook") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Publisher" HeaderText="Publisher" SortExpression="Publisher" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink id="hplink" runat="server" Text='<%# Bind("columnname")%>' NavigateUrl='<%# Bind("columnname")%>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
On NavigateUrl, you can redirect to any page and on page_load you can call any stored procedure by using SQlCommand Object.