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.
Related
The last header column of my gridview isnt aligning for some reason, im unsure why, any help?
<asp:GridView ID="gvStudents" runat="server" AutoGenerateColumns="False"
DataSourceID="SQLGetStudents" Width="100%" CssClass="table table-striped table-hover">
<alternatingrowstyle backcolor="#d0e6f4" forecolor="#545454"/>
<Columns>
<asp:BoundField DataField="PERSON_CODE" HeaderText="Student ID"
SortExpression="PERSON_CODE" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="STUDENTNAME" HeaderText="Student Name"
SortExpression="STUDENTNAME" >
<HeaderStyle Font-Bold="True" Font-Size="Larger" />
<ItemStyle Font-Bold="True" Font-Size="Larger" />
</asp:BoundField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:Label runat="server" >Add</asp:Label>
<br />
<asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkAdd" runat="server" Checked="True" onclick = "Check_Click(this)"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
The particular part of my gridview that doesnt seem to be working is here:
<asp:TemplateField HeaderStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:Label runat="server" >Add</asp:Label>
<br />
<asp:CheckBox ID="chkAll" runat="server" onclick = "checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkAdd" runat="server" Checked="True" onclick = "Check_Click(this)"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
but i thought id add all of the gridview just in case i messed up elsewhere
The Column shows up like this:
I have a gridview where the first column are check boxes, the next column is ID's. I have hidden labels on the page that need to get the current ID for any check boxes checked. The labels are specific, hlbl_pain1, hlbl_pain2, hlbl_pain3. It doenst matter which label gets which ID I just need each of the 3 hidden labels to be populated with ID's. Right now on CheckedChanged the 3 labels all update with the same value. I'm having issues looping. This is in VB.
Here's my grid:
<asp:GridView ID="gv_pain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="ds_grid_pain" ForeColor="Black" GridLines="Vertical" style="text-align: left; font-size: x-small; ">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxPain" runat="server" AutoPostBack="True" Checked="false" OnCheckedChanged="CheckBoxPain_CheckedChanged" />
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("DrugID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DrugID" InsertVisible="False" SortExpression="DrugID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DrugID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_DrugID" runat="server" Text='<%# Bind("DrugID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NickName" HeaderText="NickName" SortExpression="NickName" ItemStyle-Width="150px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DrugName" HeaderText="DrugName" SortExpression="DrugName" ItemStyle-Width="500px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan1" HeaderText="Quan1" SortExpression="Quan1">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan2" HeaderText="Quan2" SortExpression="Quan2">
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
Here are my labels:
<asp:Label ID="hlbl_pain1" runat="server" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain2" runat="server" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain3" runat="server" Visible="true"></asp:Label>
Here's what I'm trying to do in my CheckedChanged in the codebehind:
Protected Sub CheckBoxPain_CheckedChanged(sender As Object, e As System.EventArgs)
Dim row As GridViewRow
For Each row In gv_pain.Rows
Dim cbPain As CheckBox = row.FindControl("CheckBoxPain")
If cbPain.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain1.Text = lblDrugID.text
End If
Dim cbPain1 As CheckBox = row.FindControl("CheckBoxPain")
If cbPain1.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain2.Text = lblDrugID.text
End If
Dim cbPain2 As CheckBox = row.FindControl("CheckBoxPain")
If cbPain2.Checked = True Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
hlbl_pain3.Text = lblDrugID.text
End If
Next
End Sub
I can't get the value. What I do get is a blank value or videoName = " ". How can I get the value of videoName? In the rowdeleting event, I am using Rows(e.Index).Cells(2).Text to get the value but it is blank. Is there another way to get the field, "videoname"?
Protected Sub GridView1_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)
Dim videoName As String = gridview1.Rows(e.RowIndex).Cells(2).Text
Dim val As String = videoName
If File.Exists(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "\contents\published" + videoName) Then
File.Delete(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "\contents\published" + videoName)
End If
End Sub
<asp:GridView id="GridView1" runat="server" Width="680px" GridLines="None" DataSourceID="SqlDataSource2" DataKeyNames="id" CellSpacing="1" CellPadding="3" BorderWidth="2px" BorderStyle="Ridge" BorderColor="White" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" EmptyDataText="No Record Found" OnRowDeleting="GridView1_RowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="9" >
<Columns>
<asp:BoundField HeaderText="Id" DataField="Id" ReadOnly="true" visible="false" />
<asp:BoundField HeaderText="CustomerID" DataField="CustomerID" ReadOnly="true" visible="false"/>
<asp:BoundField HeaderText="VideoName" DataField="VideoName" ReadOnly="true" visible="false"/>
<asp:TemplateField>
<HeaderStyle Width="5%" />
<ItemStyle Width="5%" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" Runat="server" OnClientClick="return confirm('Are you sure you want to delete this video?');"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Clip" SortExpression="ThumbName">
<HeaderStyle Width="5%" />
<ItemStyle Width="5%" />
<ItemTemplate>
<div style="margin:2px; width:133px; background-color:rgb(68,68,68); -moz-box-shadow: 5px 5px 5px rgba(68,68,68,0.6); -webkit-box-shadow:5px 5px 5px rgba(68,68,68,0.6);box-shadow:5px 5px 5px rgba(68,68,68,0.6); zoom: 1;">
<asp:hyperlink id="link" NavigateUrl='<%# Eval("VideoName", "~/Test/playVideos2.aspx?FileName={0}&Thumb=" + Eval("ThumbName") + "&Duration=" + Eval("Duration"))%>' runat="server">
<asp:image id="img" ImageUrl='<%# String.Format("~/contents/thumbs/{0}",Eval("ThumbName"))%>' width="130" height="80" runat="server" />
</asp:hyperlink>
<asp:Label ID="lblMovieName" Text='<%#Bind("VideoName") %>' runat="server"></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<HeaderStyle Width="15%" />
<ItemStyle Width="15%" />
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%# Bind("DateCreated") %>'></asp:Label><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle Width="75%" />
<ItemStyle Width="75%" />
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>
This is prone to erros when you add or delete a column from gridview in future your code would fail again. I suggest you use a label inside template field for your MovieName field & use FindControl to find your label.
Aspx
<asp:TemplateField HeaderText="Movie Name" >
<ItemTemplate>
<asp:Label ID="lblMovieName" Text='<%#Bind("MovieName") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Code behind
protected void gvCustomer_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label lblMovieName = gvCustomer.Rows[e.RowIndex].FindControl("yourLableControlName") as Label;
// Perform your delete
}
Updated
I found that in your code you have the movieName Visibleproperty set to false. This will prevent it from rendering on page. You can either store values in DataKeys or remove visible=false to fetch desired value.
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.
when i click on the textbox which is inside the item template of gridview then onclick event should fire and then call the javascript function but my problem is that there no onclick event option in item template's textbox
plz hel p me.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView2_RowCommand"
Width="100%" GridLines="None"
style="font-family: Tahoma; font-size: xx-small" Font-Names="Tahoma"
Font-Size="XX-Small">
<Columns>
<asp:BoundField HeaderText="Status" DataField="Status" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Order" >
<ItemTemplate>
<asp:TextBox ID="TextBox1" Text='<%#Eval("ArticleOrder")%>' ReadOnly="true"
runat="server" Height="18px" Width="16px" onclick="hello();" >
</asp:TextBox>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<%--<asp:BoundField HeaderText="Order" DataField="ArticleOrder" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Center">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>--%>
<asp:BoundField HeaderText="Title" DataField="ArticleTitle" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="ImageButtonedt" runat="server" ImageUrl="~/images/newspaper_go.png"
CommandName="edt" CommandArgument='<%#Eval("ArticleID")%>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton ID="ImageButtondel" runat="server" ImageUrl="~/images/newspaper_delete.png"
CommandName="del" OnClientClick='return confirm("Are you sure you want to delete ?");' CommandArgument='<%#Eval("ArticleID")%>' />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
javascript function:
hello()
{
var divName = document.getElementById('div1');
var divFade = document.getElementById('fade');
divName.style.display = 'block';
divFade.style.display = 'block';
}
Cant tell from you code.. but if thats exactly what you have you need to define your javascript function as a function:
function hello() {
var divName = document.getElementById('div1');
var divFade = document.getElementById('fade');
divName.style.display = 'block';
divFade.style.display = 'block';
}
also, 'div1' and 'fade' are not defined in your code