I have two gridviews on different pages, with almost the same code, and one is working but the other isn't...
Here's the code of the one that is NOT working:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true" EnablePartialRendering= "true">
</asp:ScriptManager>
<div id="gridview">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" style="font-family: Verdana, Arial, Sans-Serif;"
DataKeyNames="id"
CssClass="gridview" BackColor="#CCCCCC"
BorderStyle="Inset" BorderWidth="2px" BorderColor="GrayText"
CellPadding="1"
CellSpacing="5"
HeaderStyle-HorizontalAlign="Center"
OnRowDataBound="GridView1_RowDataBound"
ForeColor ="Black" RowStyle-CssClass="gridview"
OnRowCommand="GridView1_RowCommand"
ViewStateMode="Enabled" AllowPaging="True"
OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="3">
<AlternatingRowStyle BackColor="LightGray" />
<columns>
<asp:BoundField HeaderText="ID" DataField="id" />
<asp:BoundField HeaderText="PRIORIDADE" DataField="prioridade"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="SITUAÇÃO" DataField="situacao"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="RESPONSAVEL" DataField="responsavel"
HeaderStyle-Width="65px" ItemStyle-HorizontalAlign="Center" >
<HeaderStyle Width="65px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="DATA DE CADASTRO" DataField="dt_cadastro"
DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px"
ItemStyle-HorizontalAlign="Center" >
<HeaderStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="PREVISÃO DE TÉRMINO" DataField="previsao_termino"
DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="80px"
ItemStyle-HorizontalAlign="Center" >
<HeaderStyle Width="80px" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="PROJETO" DataField="projeto"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="FUNCIONALIDADE" DataField="funcionalidade"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="CLUBE" DataField="clube"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderStyle-Width="70px" HeaderText="VISUALIZAR" >
<ItemTemplate>
<asp:Button ID="Btn_Visualizar" runat="server" Text="VISUALIZAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial"
CommandName="visualizar" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" />
</ItemTemplate>
<HeaderStyle Width="70px" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="66px" HeaderText="ALTERAR">
<ItemTemplate>
<asp:Button ID="Btn_Alterar" runat="server" Text="ALTERAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial"
CommandName="editar" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" />
</ItemTemplate>
<HeaderStyle Width="66px" />
</asp:TemplateField>
</columns>
<EditRowStyle ForeColor="Black" CssClass="GridViewEditRow" />
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" />
<PagerStyle BackColor="#6600FF" ForeColor="Black" HorizontalAlign="Left"
Font-Size="8pt" />
<RowStyle BackColor="White" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
And Here is my codebehind:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["login"] == null)
{
Response.Redirect("~/Login.aspx");
}
else
{
if (!Page.IsPostBack)
{
GridView1.DataSource = _ch.BuscaChamadosAtivos();
GridView1.DataBind();
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = _ch.BuscaChamadosAtivos();
GridView1.DataBind();
}
Even the numbers of the pagging does not shows up...
Obs: Two of these fields will come ALWAYS empty... May this be causing me this problem ? I don't think so... But I said anyway.
Related
I've got a GridView that I'd like to have two buttons with two different actions. I had tried making both of them select buttons, which would be optimal, but I can't get ASP.NET to tell me which of the two buttons triggered the event. It'll tell you the row index, but not the column from what I see.
I changed one of my buttons to an edit button so that it then calls a different method, but then it puts the row into edit mode. I do not see a way to cancel the edit, AND it is mis-using the intended use of the code.
The buttons are in the first and last columns of the gv.
<asp:GridView ID="gvMedList" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="dsMedList" GridLines="Vertical" OnSelectedIndexChanged="gvMedAction" OnDataBound="gvMedList_DataBound" OnRowEditing="gvRefillButton">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ButtonType="Button" SelectText=" -STOP- " ShowSelectButton="True" ShowCancelButton="False" />
<asp:CheckBoxField DataField="Active_Med" HeaderText="Active" SortExpression="Active_Med" >
<HeaderStyle Width="50px" />
<ItemStyle HorizontalAlign="Center" />
</asp:CheckBoxField>
<asp:BoundField DataField="Medication_List_ID" HeaderText="Medication_List_ID" InsertVisible="False" ReadOnly="True" SortExpression="Medication_List_ID" >
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Label_Name" HeaderText="Medication" SortExpression="Label_Name" >
<HeaderStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Med_Form" HeaderText="Form" SortExpression="Med_Form" >
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="dose" HeaderText="Dose" SortExpression="dose" >
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="dose_unit" HeaderText="Unit" SortExpression="dose_unit" >
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Med_Amt" HeaderText="Med_Amt" SortExpression="Med_Amt" Visible="False" />
<asp:BoundField DataField="Amount_Unit" HeaderText="Amount_Unit" SortExpression="Amount_Unit" Visible="False" />
<asp:BoundField DataField="Med_Sched_Label" HeaderText="Frequency" SortExpression="Med_Sched_Label" >
<HeaderStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="Med_Dispense" HeaderText="Dispense" SortExpression="Med_Dispense" >
<HeaderStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Dispense_Unit" HeaderText="Unit" SortExpression="Dispense_Unit" ShowHeader="False" >
<ItemStyle Width="50px" />
</asp:BoundField>
<asp:BoundField DataField="Med_Refill" HeaderText="Med_Refill" SortExpression="Med_Refill" Visible="False" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments" />
<asp:CommandField ButtonType="Button" EditText="-REFILL-" ShowCancelButton="False" ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#27627E" Font-Bold="True" ForeColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" Height="20px" HorizontalAlign="Center" VerticalAlign="Middle" Width="125px" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
Use the CommandName property
Front-End
<asp:GridView ID="gvMedList" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="dsMedList" GridLines="Vertical" OnSelectedIndexChanged="gvMedAction" OnDataBound="gvMedList_DataBound" OnRowEditing="gvRefillButton" OnRowCommand="gvMedList_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ColumnName">
<ItemTemplate>
<asp:Button ID="btnDoSomething" runat="server" CommandName="DoSomething" Text="Do Something" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AnotherColumn">
<ItemTemplate>
<asp:ImageButton ID="btnImageSomething" runat="server" CommandName="DoSomethingElse" ImageUrl="~/images/yes.png" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-Behind (assumed C#...if you need VB let me know)
protected void gvMedList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DoSomething")
{
// code to execute
}
if (e.CommandName == "DoSomethingElse")
{
// code to execute
}
}
I have grid view
<cc1:GridView ID="gvMenu" runat="server" AllowPaging="False" AllowSorting="False"
AutoGenerateColumns="False" CssClass="mGrid" Width="100%" DataKeyNames="ID,MenuName"
DataSourceID="OdsGetMenuDetails" OnRowDataBound="gvMenu_RowDataBound">
<%--OnRowDataBound="gvAddLeave_RowDataBound"--%>
<AlternatingRowStyle CssClass="alt" />
<HeaderStyle CssClass="GridViewHeaderStyle" />
<PagerStyle CssClass="pgr" />
<RowStyle Wrap="false" />
<EmptyDataRowStyle BackColor="#edf5ff" Height="300px" HorizontalAlign="Center" VerticalAlign="Middle" />
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
<Columns>
<asp:TemplateField HeaderText="Sr.No">
<ItemTemplate>
<%# (gvMenu.PageIndex * gvMenu.PageSize) + Container.DataItemIndex + 1%>
</ItemTemplate>
<HeaderStyle CssClass="style4" ForeColor="White" Width="5%" />
<ItemStyle CssClass="style4" />
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="Menu ID" SortExpression="ID" Visible="false">
<HeaderStyle CssClass="style4" Width="100px" HorizontalAlign="Left" ForeColor="White" />
<ItemStyle CssClass="style4" />
</asp:BoundField>
<asp:BoundField DataField="MenuName" HeaderText="MenuName" SortExpression="MenuName">
<HeaderStyle CssClass="style4" Width="80%" HorizontalAlign="Left" ForeColor="White" />
<ItemStyle CssClass="style4" />
</asp:BoundField>
<asp:TemplateField HeaderText="View">
<HeaderTemplate>
<asp:CheckBox ID="chkHeaderApprove" runat="server" Text="View" onclick="javascript:SelectAllCheckboxes1(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkApprove" runat="server" Checked='<%# Eval("ViewStatus").ToString().Trim() == "1" ? true : false %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</cc1:GridView>
with this objectDataSource
<asp:ObjectDataSource ID="OdsGetMenuDetails" runat="server" SelectMethod="GetMenuName"
EnablePaging="true" TypeName="AdsWorksDBMenuAuthorizationDAL" StartRowIndexParameterName="startIndex"
SortParameterName="sortBy" MaximumRowsParameterName="pageSize" SelectCountMethod="GetMenuCount">
</asp:ObjectDataSource>
I want to do the <asp:CheckBox ID="chkHeaderApprove" > checked when all my <asp:CheckBox ID="chkApprove"> is checked??
I am not able to do this please help me some more....
Add this:
<asp:CheckBox ID="chkApprove" runat="server" Checked='<%# Eval("ViewStatus").ToString().Trim() == "1" ? true : false %>' OnCheckedChanged="chkApprove_CheckChanged"/>
And in code behind:
protected void chkApprove_CheckChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
GridView g1 = (GridView)cb.Parent.Parent;
foreach (GridViewRow item in g1.Rows)
{
CheckBox currentCheckBox = (CheckBox)item.FindControl("chkApprove");
if (currentCheckBox.Checked != true)
return;
}
CheckBox chkHeaderApprove = (CheckBox)g1.FindControl("chkHeaderApprove");
chkHeaderApprove.Checked = true;
}
This should work.. didn't check. Anyways client side should be better, go for that.. This is just a easy server side solution.
i have filled gridview with Store procedure which needs registrationNo parameter so TEXTBOX is control parameter, and that store procedure is on server's database which receives new records from tablet device. It shows new records when i click SEARCH button after entering data in textbox but problem is that if new data is received from tablet and i hit search button then it doesn't show new data, i have to go back to home page then this page and again entering data and clicking search button, then it displays why ?
CODE:
<form id="form1" runat="server">
<div>
<asp:Button ID="btnHome" runat="server" Text="Home" CssClass="button" Width="7%" OnClick="btnHome_Click" />
</div>
<br />
<div>
<asp:Panel ID="pnlInput" runat="server" DefaultButton="btnSearch">
<asp:TextBox ID="txtboxVehicleNo" runat="server"></asp:TextBox>  
<asp:Button ID="btnSearch" Text="Search" Width="9%" CssClass="button" runat="server" OnClick="btnSearch_Click1" />
</asp:Panel>
</div>
<br />
<br />
<div>
<asp:GridView ID="gvVehicleLedger" ShowHeaderWhenEmpty="True" runat="server" CellPadding="7" DataSourceID="SqlDataSourceETTVehicleLed" ForeColor="#333333" GridLines="None" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Vehicle No" Width="100%" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Vehicle No" HeaderText="Vehicle No" ReadOnly="True" SortExpression="Vehicle No" >
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Transaction Date" HeaderText="Transaction Date" SortExpression="Transaction Date">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Engine Capacity" HeaderText="Engine Capacity" SortExpression="Engine Capacity" >
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<ItemStyle HorizontalAlign="Left" Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" >
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="No Of Months" HeaderText="No Of Months" SortExpression="No Of Months" >
<HeaderStyle HorizontalAlign="Center" Wrap="False" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" >
<HeaderStyle HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<emptydatarowstyle backcolor="#eff3fb"
forecolor="Red"/>
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceETTVehicleLed" runat="server" ConnectionString="<%$ ConnectionStrings:ETTConnectionStr %>" SelectCommand="Vehicleledger" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="txtboxVehicleNo" Name="RegistrationNo" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
.cs code:
if(!IsPostBack)
{
gvVehicleLedger.Visible = false;
}
protected void btnSearch_Click1(object sender, EventArgs e)
{
gvVehicleLedger.Visible = true;
}
after searching data you should set grid's data source which is newly data to from search
example
private void serach_click()
{
// your code to retrieve your data
gridview.datasource = your data source;
gridview.databind();
}
looks like you don't refresh your data for the gridView on searchClick. I think you should use smthng like gvVehicleLedger.databind().
(there's a blog about this topic here)
I would like to adjust footer template horizontal align as left in grid but, it's not working any one can explain please. this is my code
<asp:GridView ID="Grd_View" ShowFooter="True" runat="server" OnRowEditing="Grd_View_RowEditing" AutoGenerateColumns="False"
DataKeyNames="CustomerCode" CellPadding="4" OnRowCommand="Grd_View_RowCommand" GridLines="None" ShowHeader="True"
AllowPaging="True" AllowSorting="True" CssClass="style2" ForeColor="#333333" OnRowDataBound="Grd_View_RowDataBound"
OnRowDeleting="Grd_View_RowDeleting" >
<FooterStyle BackColor="#555555" ForeColor="White" HorizontalAlign="Center" Font-Bold="True" />
<Columns>
<asp:BoundField DataField="CustomerCode" HeaderText="Customer Code" InsertVisible="False"
ReadOnly="True" SortExpression="CustomerCode" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="CustomerName" HeaderText="Customer Name" SortExpression="CustomerName" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="TellNo" HeaderText="Tell No" SortExpression="TellNo" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="FaxNo" HeaderText="Fax No" SortExpression="FaxNo" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" ItemStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="PIC" HeaderText="Person in Contact" SortExpression="PIC" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" runat="server" CommandArgument='<%#Eval("CustomerCode")%>' CommandName="Edit" Text="Edit">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandArgument='<%#Eval("CustomerCode")%>' CommandName="Delete" Text="Delete">
</asp:LinkButton>
</ItemTemplate>
<FooterTemplate> <asp:LinkButton ForeColor="white" ID="btnNew" runat="server" CommandArgument='<%#Eval("CustomerCode")%>' CommandName="New" Text="New">
</asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#777777" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#555555" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
Try using the below:
<FooterTemplate>
<asp:LinkButton ForeColor="white" ID="btnNew" runat="server" CommandName="New" Text="New">
</asp:LinkButton>
</FooterTemplate>
<FooterStyle HorizontalAlign="Left" />
The Reason your footer template will always be in right is because you are creating it as the last column in the GridView along with the Delete column.
To solve this you need to create the footer template in the first column or I'll recommend just putting the footer template inside with edit template field in the first column and the delete template field in the second column.
i am trying to create a dynamic Gridview on a ASP.NET page and i have multiple rows, and added a CheckBox Column.
<body>
<h1>Alerts</h1>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KiwiLogConnectionString %>" SelectCommand="SELECT * FROM [Syslogd]
GROUP BY MsgHostname, MsgDate, MsgTime, MsgPriority, MsgText"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" DataSourceID="SqlDataSource1" ForeColor="#333333" AllowPaging="True" PageSize="15">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField >
<ItemTemplate >
<asp:CheckBox ID ="Checkbox" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MsgDate" HeaderText="Datum" SortExpression="MsgDate" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgTime" HeaderText="Tijd" SortExpression="MsgTime" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgPriority" HeaderText="Priority" SortExpression="MsgPriority" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgHostname" HeaderText="Hostname" SortExpression="MsgHostname" ItemStyle-Wrap="false" >
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="MsgText" HeaderText="Message" SortExpression="MsgText" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:Button ID="btn_update" runat="server" OnClick="btn_update_Click" Text="Update" />
</form>
</body>
If that CheckBox is checked and the "Update" Button is clicked, i want these row(s) to be hidden. How can i manage to do that?
protected void btn_update_Click(object sender, EventArgs e)
{
}
The gridview is build up with the SQL Database, so it has to be dynamic. In foward, many thanks!
You can try the following:
protected void btn_update_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
if (((CheckBox)gvr.findcontrol("Checkbox")).Checked == true)
{
//Do stuff with checked row
gvr.Visible = false;
}
}
}
I would use javascript for something like this.