How to access UserControl value inside telerik:GridTemplateColumn through javascript - javascript

Below is the telerik grid code snippet. I need to access value of "CustomDataListId" which is in idr:JemsCustomDataColumnEditor which is inside item template through javascript. Please help.
<telerik:RadGrid ID="radCustomData" runat="server" CellSpacing="0" GridLines="None"
OnNeedDataSource="radCustomData_NeedDataSource"
ViewStateMode="Enabled" ClientSettings-Scrolling-UseStaticHeaders="true">
<MasterTableView PagerStyle-AlwaysVisible="true" AutoGenerateColumns="False" ShowHeader="false">
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn UniqueName="customDataColumn">
<InsertItemTemplate>
<idr:JemsCustomDataColumnEditor runat="server" ID="customColumnEditor" MaxLength='0'
LabelText='<%#Bind("CustomDataName") %>' IsRequired='<%#Bind("IsRequiredField") %>'
IsVisible='<%#Bind("Visible") %>' CustomDataId='<%#Bind("CustomDataId") %>' ValidationMaskId='<%#Bind("ValidationMaskId") %>'
CustomDataListId='<%#Bind("CustomDataListId") %>' DbCustomDataId='<%#Bind("DbCustomDataId") %>'
LastUpdated='<%#Bind("LastUpdated") %>' LastUpdatedBy='<%#Bind("LastUpdatedBy") %>'
DataType='<%#Bind("CustomDataTypeEnum") %>' Value='<%#Bind("CustomDataValue") %>' />
</InsertItemTemplate>
<EditItemTemplate>
<idr:JemsCustomDataColumnEditor runat="server" ID="customColumnEditor" MaxLength='0'
LabelText='<%#Bind("CustomDataName") %>' IsRequired='<%#Bind("IsRequiredField") %>'
IsVisible='<%#Bind("Visible") %>' CustomDataId='<%#Bind("CustomDataId") %>' ValidationMaskId='<%#Bind("ValidationMaskId") %>'
CustomDataListId='<%#Bind("CustomDataListId") %>' DbCustomDataId='<%#Bind("DbCustomDataId") %>'
LastUpdated='<%#Bind("LastUpdated") %>' LastUpdatedBy='<%#Bind("LastUpdatedBy") %>'
DataType='<%#Bind("CustomDataTypeEnum") %>' Value='<%#Bind("CustomDataValue") %>' />
</EditItemTemplate>
<ItemTemplate>
<idr:JemsCustomDataColumnEditor runat="server" ID="customColumnEditor" MaxLength='0'
LabelText='<%#Bind("CustomDataName") %>' IsRequired='<%#Bind("IsRequiredField") %>'
IsVisible='<%#Bind("Visible") %>' CustomDataId='<%#Bind("CustomDataId") %>' ValidationMaskId='<%#Bind("ValidationMaskId") %>'
CustomDataListId='<%#Bind("CustomDataListId") %>' DbCustomDataId='<%#Bind("DbCustomDataId") %>'
LastUpdated='<%#Bind("LastUpdated") %>' LastUpdatedBy='<%#Bind("LastUpdatedBy") %>'
DataType='<%#Bind("CustomDataTypeEnum") %>' Value='<%#Bind("CustomDataValue") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
</telerik:RadGrid>

Related

get client id of image control inside repeater inside gridview

How do I get client id of image control
<asp:GridView ID="gv" OnRowDataBound="GetItems" runat="server" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Font-Names="tahoma" Font-Size="8pt" AutoGenerateColumns="False" Height="154px" Width="929px">
<Columns>
<asp:TemplateField HeaderText="pic">
<ItemTemplate>
<asp:Repeater ID="pictures" runat="server">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" height="120" width="90" ImageUrl='<%# Eval("ImageUrl") %>' onclick="DisplayNewImageInWidnow();" />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I use this code but it doesn't work
function DisplayNewImageInWidnow()
{
var img = document.getElementById('<%=gv.FindControl("pictures").FindControl("Image1").ClientID %>').src
OnClientClick="return DisplayNewImageInWidnow();"
or prevent server side from running
OnClientClick="DisplayNewImageInWidnow();return false;"
then
function DisplayNewImageInWidnow(obj)
{
var imgId = obj.id;
}

How to call id from gridview in javascript window.open in asp .net?

I'm new to .net and jquery.
My gridview shows like this http://s3.postimg.org/erfrxh25f/untitled.jpg
Here is my loginfo click event.
protected void loginfo_click(Object sender, EventArgs e)
{
Button btn = (Button)(sender);
Response.Write("<script>");
Response.Write("window.open('loginfo.aspx?id=" + + "','_blank')");
Response.Write("</script>");
}
gridview:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Book_id" DataSourceID="SqlDataSource1"
OnRowCommand="GridView1_RowCommand"
EnablePersistedSelection="True" BackColor="White"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Height="240px"
Width="755px" BorderColor="Red" BorderWidth="2px">
<Columns>
<asp:BoundField DataField="Book_id" HeaderText="Book_id" InsertVisible="False"
ReadOnly="True" SortExpression="Book_id" >
<ControlStyle BorderColor="Red" />
</asp:BoundField>
<asp:BoundField DataField="Book_name" HeaderText="Book_name" SortExpression="Book_name" />
<asp:BoundField DataField="Author_name" HeaderText="Author_name" SortExpression="Author_name" />
<asp:BoundField DataField="Publisher_name" HeaderText="Publish_name" SortExpression="Publisher_name" />
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button runat="server" ID="btnedit" Text="Edit" CommandName="EditRow"></asp:Button>
</ItemTemplate>
<ControlStyle BorderColor="#CCFF66" BackColor="#FF0066" ForeColor="White" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:Button runat="server" ID="btndelete" Text="Delete" CommandArgument='<%# Eval("Book_id") %>' CommandName="Deleterow"></asp:Button>
</ItemTemplate>
<ControlStyle BackColor="#FF0066" ForeColor="White" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Log Info">
<ItemTemplate>
<asp:Button runat="server" ID="btnloginfo" Text="Log-Info" CommandArgument='<%# Eval("Book_id") %>' Onclick="loginfo_click"/>
</ItemTemplate>
<ControlStyle BackColor="#FF0066" ForeColor="White" />
</asp:TemplateField>
</Columns>
<EditRowStyle BorderColor="Red" />
<HeaderStyle BackColor="#FF0066" BorderColor="#CCFFFF" ForeColor="White"
Height="50px" Width="50px" />
<SelectedRowStyle BackColor="#FF66FF" />
</asp:GridView>
I just confused how to call bookid in window.open.,
Any help would be highly appreciated.
Thanks,
update:
loginfo.css:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = Connection.DBconnection();
SqlCommand com = new SqlCommand("sp_logdetails", con);
com.CommandType = CommandType.StoredProcedure;
}
loginfo.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Book_id" EnablePersistedSelection="True" BackColor="White" Height="240px"
Width="755px" BorderColor="Red" BorderWidth="2px">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
ReadOnly="True" SortExpression="Book_id" >
<ControlStyle BorderColor="Red" />
</asp:BoundField>
<asp:BoundField DataField="bookid" HeaderText="bookid" SortExpression="bookid" />
<asp:BoundField DataField="studentid" HeaderText="studentid" SortExpression="studentid" />
<asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />
<asp:BoundField DataField="returndate" HeaderText="returndate" SortExpression="returndate" />
<asp:BoundField DataField="returnstatus" HeaderText="returnstatus" SortExpression="returnstatus" />
</Columns>
</asp:GridView>
You are already setting Book_id as a CommandArgument, so you can get the value from there directly by accessing the button through sender object.
protected void loginfo_click(Object sender, EventArgs e)
{
Button btn = (Button)sender;
Response.Write("<script>");
Response.Write("window.open('loginfo.aspx?id=" + btn.CommandArgument + "','_blank')");
Response.Write("</script>");
}

How to get an element in each loop of gridview in javascript

I want to get the IdQueue's of the Queues I have checked in the check box, in java script.
For example, if i have checked boxes of IdQueue's 3 and 5, i want that the JS will alert me the IdQueue of them.
I need your help with this JS.
Thanks ahead.
<div data-role="popup" align=center id="Div1" style="width:600px; height:400px; direction:rtl; background-color:white">
<asp:GridView ID="GridView1" ClientIDMode="Static" runat="server" AllowPaging="False" AutoGenerateColumns="false"
OnRowCommand="grd_Threshold_Command" CssClass="text" Width="80%" OnRowDataBound="grd_Threshold_OnRowDataBound" >
<HeaderStyle CssClass="gridHeader" />
<RowStyle CssClass="gridRow" VerticalAlign="Top" />
<Columns>
<asp:TemplateField HeaderText="IdQueue" Visible="true">
<ItemTemplate>
<asp:Label ID="lblCSQCode" runat="server" Text='<%# Bind("CSQid") %>' BorderStyle="none"
BorderWidth="0px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NameQueue" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblCSQName" runat="server" Text='<%# Bind("Name") %>' BorderStyle="none"
BorderWidth="0px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IntervalQueue" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList Visible="true" Enabled="true" ID="ddlResalution" EnableViewState="true"
runat="server" Width="148px">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ChooseQueue" HeaderStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="cbk1" runat="server" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Label ID="lblMust" runat="server" Text="" ForeColor="Red"></asp:Label>
<br />
<div style="width: 100px; margin: 0 auto;">
<asp:ImageButton ID="ImgBtnSave" runat="server" ImageUrl="~/Images/glossyGreenOK.gif"
Height="40px" OnClick="lnkBranchReport_Click" Width="40px" />
</div>
<div style="width: 100px; margin: 0 auto;color: #003399; font-weight: bold;
font-size: 14px;">
<asp:LinkButton ID="lnbSave" runat="server" OnClientClick="CheckedBoxes()" >ok</asp:LinkButton>
</div>
</div>
Try this:
<asp:CheckBox ID="cbk1" runat="server" EnableViewState="true" data-id='<%# Eval("CSQid") %>' />
<asp:LinkButton ID="lnbSave" runat="server" OnClientClick="CheckedBoxes();return false();" >ok</asp:LinkButton>
Add a custom attribute to checkbox so we can directly access id from here instead getting from label lblCSQCode. After that add this javascript
First way
$('#<%=lnbSave.ClientID%>').on('click', function() {
var arr = [];
var selectedID = '';
$('#<%=GridView1.ClientID%> tr td input[type=checkbox]:checked').each(function() {
var id = $(this).parent().attr('data-id');
arr.push(id);
});
selectedID = arr.join();
//alert(selectedID);
});
Second way
function CheckedBoxes() {
var arr = [];
var selectedID = '';
$('#<%=GridView1.ClientID%> tr td input[type=checkbox]:checked').each(function() {
var id = $(this).parent().attr('data-id');
arr.push(id);
});
selectedID = arr.join();
//alert(selectedID);
}

View Details (all the Fields) when clicking on Select Button in Gridview

How can I get a view of all the fields in a new asp page when clicking on the Button "Select" in Gridview in a webform asp page. I think I have to create a function which will be called on "OnClientClick". Here's my code. How could I perform this task? thank you very much in advance, best regards
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="ObjectDataSource1" AllowPaging="True"
AllowSorting="True">
<Columns>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="CancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="SelectButton" runat="server" OnClientClick="" CausesValidation="False"
CommandName="Select" Text="Select"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
For button click event try:
<asp:gridview id="NewGridView"
datasourceid="NewSqlDataSource"
autogeneratecolumns="false"
onrowcommand="NewGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select People"
text="Select"/>
</columns>
</asp:gridview>
void NewGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="Select")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = NewGridView.Rows[index];
}
}
Or check link,
https://msdn.microsoft.com/en-us/library/bb907626.aspx

Clear/Reset file upload control in grid view

I have multiple file upload control in asp.net grid view,i want to clear/reset file upload control when wrong file selection.
fileupload1 btnReset1
fileupload2 btnReset2
...
when i click btnReset2 then only clear value for fileupload2
How can i do this using java script.
Thank you all in advance
My code is as below.
JS Code:-
<script type="text/javascript">
function hi(ob) {
debugger;
var grid = document.getElementById("<%= GridView1.ClientID %>");
var inputs = grid.getElementsByTagName("input");
var fileUpload;
var strRowNo = ob.id.toString().split("_")[3];//get row number
alert(strRowNo);
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "file") {
fileUpload = inputs[i];
if (i == strRowNo) {
fileUpload.value = "";
}
}
}
}
</script>
//Aspx Code:-
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="A" HeaderText="A" />
<asp:BoundField DataField="B" HeaderText="B" />
<asp:BoundField DataField="C" HeaderText="C" />
<asp:TemplateField HeaderText="File">
<ItemTemplate>
<div id="fuDiv" runat="server">
<asp:FileUpload ID="fupFile" runat="server" />
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reset">
<ItemTemplate>
<asp:Image ID="ibtnReset" runat="server" onClick="javascript:hi(this);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="A" HeaderText="A" />
<asp:BoundField DataField="B" HeaderText="B" />
<asp:BoundField DataField="C" HeaderText="C" />
<asp:TemplateField HeaderText="File">
<ItemTemplate>
<div id="fuDiv" runat="server">
<asp:UpdatePanel ID="update_fupFile" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload ID="fupFile" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ibtnReset" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Reset">
<ItemTemplate>
<asp:UpdatePanel ID="update_fupFile" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Image ID="ibtnReset" runat="server" onClick="javascript:hi(this);" />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

Categories

Resources