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
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 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 a gridview with pregenerated columns
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
CellPadding="4" GridLines="Horizontal">
<RowStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="MenuID" >
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("MenuID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="MenuParentID" >
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("MenuParentID") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Particulars">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Particulars") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="250px" />
</asp:TemplateField>
<asp:BoundField DataField="Options" HeaderText="Options"
ItemStyle-HorizontalAlign="Center" >
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Menu(M)" >
<ItemTemplate>
<asp:CheckBox ID="chkMenu" runat="server" OnCheckedChanged="chkMenu_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Add(A)">
<ItemTemplate>
<asp:CheckBox ID="chkAdd" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit(E)">
<ItemTemplate>
<asp:CheckBox ID="chkEdit" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete(D)">
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
</asp:GridView>
want to fill the grid from database and check/uncheck the checkboxes from database condition. How to fill the gridview ...................................................................................
On which condition you want to check /Un-check the chechbox?
you can write code on RowDataBound event of grid.
void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// here check the condition and find the check box of current row and set it checked/uncheked
}
}
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 a nested datagrid seen below. When I click lnkSec, I want checkboxes of dgrIslem datagrid to be checked. How can I do it with javascript or Jquery?
<asp:datagrid id="dgrMenu" runat="server" Width="100%" GridLines="Horizontal" ShowHeader="False"
Height="8px" BorderWidth="1px" BorderColor="Gainsboro" CellPadding="0" AutoGenerateColumns="False"
AlternatingItemStyle-BackColor="#f5f5f5" SelectedItemStyle-BackColor="LightSteelBlue" ItemStyle-BackColor="White">
<SelectedItemStyle BackColor="LightSteelBlue"></SelectedItemStyle>
<AlternatingItemStyle BackColor="WhiteSmoke"></AlternatingItemStyle>
<ItemStyle BackColor="White"></ItemStyle>
<HeaderStyle ForeColor="White" CssClass="ms-formlabel DataGridFixedHeader" BackColor="SteelBlue"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="ID_MENU"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="ID_PARENT"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="DS_PAGE"></asp:BoundColumn>
<asp:BoundColumn DataField="DS_MENU" HeaderText="Menü">
<HeaderStyle Width="200px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
Seç/Kaldır
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="İşlemler">
<HeaderStyle Width="150px"></HeaderStyle>
<ItemTemplate>
<table id="tablo">
<tr><td>
<asp:DataGrid id="dgrIslem" runat="server" Font-Size="7pt" Width="98%" AutoGenerateColumns="False"
CellPadding="0" BorderWidth="0px" Font-Names="Verdana">
<HeaderStyle Font-Size="1pt"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<HeaderStyle HorizontalAlign="Center" Width="25px"></HeaderStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkSec" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="false" DataField="DS_ACIKLAMA"></asp:BoundColumn>
<asp:BoundColumn Visible="false" DataField="ID_MENU_ISLEM"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Here is a sample with JQuery that I've done before. You can apply it to your grid too :
<asp:GridView runat="server" ID="grid"></asp:GridView>
<input type="button" onclick="uncheckCheckBoxes()" value="UnCheck" />
<input type="button" onclick="checkCheckBoxes()" value="Check" />
<script>
function uncheckCheckBoxes()
{
var gridClientID = '<%= grid.ClientID %>';
jQuery.each($("#" + gridClientID + " input[type='checkbox']"), function ()
{
this.checked = false;
});
}
function checkCheckBoxes()
{
var gridClientID = '<%= grid.ClientID %>';
jQuery.each($("#" + gridClientID + " input[type='checkbox']"), function ()
{
this.checked = true;
});
}
</script>
$("#lnkSec").click(function(e){
$("input:checkbox",$(this).parent().next()).attr("checked",true);
})
or
....
<asp:TemplateColumn>
<ItemTemplate>
<a href="#" id="lnkSec" onclick="javascript:SelectSubCheckboxes(this);">
Seç/Kaldır</a>
</ItemTemplate>
</asp:TemplateColumn>
...
function SelectSubCheckboxes(lnkSec){
$("input:checkbox",$(lnkSec).parent().next()).attr("checked",true);
})