Accessing the value of a passed in argument to click event c# - c#

I have a gridview defined like this...
<asp:GridView runat="server" id="gvProjectLineage"
ShowFooter="false"
DataKeyNames="projectLineageID"
AutoGenerateColumns="False"
AllowPaging="false"
AllowSorting="false"
RowStyle-CssClass="shade" CellSpacing="1"
AlternatingRowStyle-CssClass="unshade"
BorderColor="Transparent"
DataSourceID="gvProjectLineageDataSource"
Width="100%">
<HeaderStyle HorizontalAlign="Left" Font-Underline="true"></HeaderStyle>
<Columns>
<asp:BoundField ReadOnly="True"
HeaderText="Lineage ID"
InsertVisible="false"
DataField="projectLineageID"
HeaderStyle-CssClass="columnHeader"
ItemStyle-VerticalAlign="Top"
Visible="false">
</asp:BoundField>
<asp:BoundField ReadOnly="True"
HeaderText="Relationship type"
InsertVisible="false"
DataField="projectRelationshipType"
HeaderStyle-CssClass="columnHeader"
ItemStyle-VerticalAlign="Top"
Visible="true">
</asp:BoundField>
<asp:BoundField ReadOnly="True"
HeaderText="Related Project"
InsertVisible="false"
DataField="projectTitle"
HeaderStyle-CssClass="columnHeader"
ItemStyle-VerticalAlign="Top"
Visible="true">
</asp:BoundField>
<asp:TemplateField ShowHeader="False"
HeaderStyle-Font-Underline="false"
ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="btnDelete"
CommandArgument='<%# Eval("projectLineageID") %>'
CommandName="Delete"
runat="server">
<img style="border:none;"
src="/content/images/icon/deleteIcon.png"
title="Delete this lineage" />
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False"
HeaderStyle-Font-Underline="false"
ItemStyle-HorizontalAlign="Left"
FooterStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:LinkButton ID="btnDeleteAll"
CommandArgument='<%# Eval("projectLineageID") %>'
runat="server"
OnClick="btnDeleteAll_Click" >
<img style="border:none;"
src="/content/images/icon/deleteIcon.png"
title="Delete this lineage AND it's reciprocal lineage" />
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>There are currently no relationships identified for this S&T project.</EmptyDataTemplate>
</asp:GridView>
The first "delete" button calls a simple delete query and it works fine to delete the selected row from the table. However, when I call the 2nd delete button ("DeleteAll"), I want to use the [projectLineageID] to find the related lineage records for a project and delete them all at once.
When I call the 2nd delete function "onclick" as follows, I get nothing in column [0].
protected void btnDeleteAll_Click(object sender, EventArgs e)
{
//Delete lineage and reciprocal lineage for relationship types 1 (Transitioned from) and 2 (Transitioned to)
util u = new util();
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string strRelID = grdrow.Cells[0].Text;
int intRelID = System.Convert.ToInt32(grdrow.Cells[0].Text);
string relType = grdrow.Cells[1].Text;
string relProj = grdrow.Cells[2].Text;
Response.Write ("Deleting relationship between " + projectID + " and the project in column 3 " + relID + " " + relType + " " + relProj + " :");
}
How do I get the projectLineageID to pass it to the query?
And, why can't I display it? Even if I try to "convert" it, I get an error telling me the "Input string was not in a correct format."
Thanks,
Bob

Related

ASP.Net GridView unsorted afrer PostBack

I have a custom GridView in asp.net Page. In PageLoad data will be bound to the grid.
protected void Page_Load(Object sender, EventArgs e)
{
InitDisplayMode(sender);
}
private void InitDisplayMode(Object sender)
{
pnlDetails.Visible = SafetyKeyId != -1;
if (!Page.IsPostBack)
{
BindValues();
}
// some other stuff
}
private void BindValues()
{
MyStrongTypedDataTable tbl = new BusinessObject.GetData();
dataGrid.DataSource = tbl;
dataGrid.DataBind();
}
Grid View Makrup
<asp:GridView ID="dataGrid" runat="server" AutoGenerateColumns="False" OnRowCreated="OnRowCreated"
AllowSorting="true" BorderWidth="0" CellPadding="2" CssClass="subitem w100p"
AllowPaging="true" PageSize="25" RowStyle-Wrap="false" HeaderStyle-Wrap="false"
OnPageIndexChanging="PageGrid" OnRowDataBound="dataGrid_RowDataBound" PagerSettings-Mode="Numeric"
PagerSettings-Position="Bottom" OnSorting="SortGrid" OnRowDeleting="RowDeleting">
<RowStyle CssClass="itemRowStyle"/>
<AlternatingRowStyle CssClass="alternatingItemRowStyle"/>
<HeaderStyle CssClass="headerRowStyle"/>
<Columns>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:HyperLink ID="lnkDetail" runat="server" meta:resourcekey="lnkDetail" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_file.png" %>'
NavigateUrl="~/BrandMgmt/BrandMgmtPublicKey.aspx?"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:HyperLink ID="lnkEdit" runat="server" meta:resourcekey="lnkEdit" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_edit.png" %>'
NavigateUrl="~/BrandMgmt/BrandMgmtPublicKey.aspx?"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle">
<ItemTemplate>
<asp:ImageButton ID="cmdDelete" Width="16" Height="16" runat="server" ImageUrl='<%# "~/App_Themes/" + Page.Theme + "/icons/16/icon_delete.png" %>'
CommandName="Delete" CommandArgument='<%# Eval("SafetyKeyId") %>' OnCommand="OnDelete"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="KeyOwnerIdentifier" HeaderText="KeyOwnerIdentifier" meta:resourcekey="ColumnKeyOwnerIdentifier"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="KeyOwnerIdentifier"/>
<asp:BoundField DataField="SafetyKeyName" HeaderText="SafetyKeyName" meta:resourcekey="ColumnSafetyKeyName"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="SafetyKeyName"/>
<asp:BoundField DataField="SafetyKeyTypeId" HeaderText="SafetyKeyTypeId" meta:resourcekey="ColumnSafetyKeyTypeId"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="SafetyKeyTypeId"/>
<asp:BoundField DataField="KeyIndex" HeaderText="KeyIndex" meta:resourcekey="ColumnKeyIndex"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="KeyIndex"/>
<asp:BoundField DataField="FromDate" HeaderText="FromDate" meta:resourcekey="ColumnFromDate"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="FromDate"/>
<asp:BoundField DataField="ToDate" HeaderText="ToDate" meta:resourcekey="ColumnToDate"
ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle" SortExpression="ToDate"/>
<asp:TemplateField ItemStyle-CssClass="itemFieldStyle" HeaderStyle-CssClass="headerFieldStyle"
meta:resourcekey="ColumnPublicKey" SortExpression="PublicKey">
<ItemTemplate>
<div style="max-width: 200px; overflow-y: scroll;">
<asp:Label runat="server" Text='<%# Eval("PublicKey") %>'/>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Grid hat 3 ImageButtons for detail view, editing and deleting per row. DetaliView Button adds additional Table with data to the Page. Editing makes this Table editable. If the grid is sorted and any of those buttons is beeing clicked, Page loads and any sorting is lost.
How can I maintain the sort setting in PostBack after clicking any of those buttons?

Unable to get posted file name in GridView when uploading file

Unable to get posted file name in GridView when uploading file.
Here is what I tried with.
ASPX File content is shown below:
<asp:GridView ID="GVProtocol" runat="server" AllowPaging="True"
HorizontalAlign="Center" CssClass="DGList" HeaderStyle-CssClass="DGHeader"
RowStyle-CssClass="DGRow" AlternatingRowStyle-CssClass="DGRowAlt" OnRowCommand="GVProtocol_RowCommand"
OnPageIndexChanging="GVProtocol_PageIndexChanging" Height="90px" Width="100%" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="SL NO" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20">
<ItemTemplate>
<%# (( ( GridView ) ( ( GridViewRow ) Container ).Parent.Parent ).PageSize + Container.DataItemIndex + 1)- 15 %>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:BoundField HeaderText="Name" DataField="NAME" />
<asp:BoundField HeaderText="Unit" DataField="UNIT" />
<asp:BoundField HeaderText="Standard Value" DataField="STANDARD_VALUE" />
<asp:TemplateField HeaderText="Upload XML" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:FileUpload ID="FileUpload" runat="server" EnableViewState="true" />
<asp:Button runat="server" ID="btnUpload" Text="upload" CommandArgument="<%# Container.DataItemIndex %>" CommandName="upload" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FilePath" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="200">
<ItemTemplate>
<asp:Label runat="server" ID="lblFilePath">-</asp:Label>
<asp:LinkButton ID="btnDownload" runat="server" CommandName="download" CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pagerStyle" />
<HeaderStyle Wrap="False" CssClass="DGHeader" />
<RowStyle CssClass="DGRow" />
<AlternatingRowStyle CssClass="DGRowAlt" HorizontalAlign="Center" />
</asp:GridView>
This is the CodeBehind file for the above ASPX content:
protected void GVProtocol_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
int Index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "upload")
{
string strFilePathTemp = Server.MapPath("~/ProtocolCommunication/");
//int Index = ((GridViewRow)((sender as Control)).NamingContainer).RowIndex;
LinkButton lbDownload = (LinkButton)GVProtocol.Rows[Index].FindControl("btnDownload");
lbDownload.Text = "<span class='glyphicon glyphicon-download-alt'>";
Label lblFilePathTemp = (Label)GVProtocol.Rows[Index].FindControl("lblFilePath");
lblFilePathTemp.Text = strFilePathTemp;
FileUpload fileUpload = (FileUpload)GVProtocol.Rows[Index].FindControl("FileUpload");
if(fileUpload != null)
{
string fileName = Path.GetFileName(fileUpload.PostedFile.FileName);
fileUpload.PostedFile.SaveAs(strFilePathTemp + fileName);
}
}
if (e.CommandName == "download")
{
Label lblFilePathTemp = (Label)GVProtocol.Rows[Index].FindControl("lblFilePath");
string fileNameAndPath = lblFilePathTemp.Text.ToString();
string file = Path.GetFileName(fileNameAndPath);
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(fileNameAndPath));
Response.TransmitFile(Server.MapPath("~/ProtocolCommunication/"));
Response.End();
}
}
catch(Exception ex)
{
throw ex;
}
}
Looking for possible solution for the above problem.
I got solution,,by using
asp:updatePanel control with postbacktrigger to hold the control ID's which are dynamically created in girdview. and using this you can upload and download files to any of the gridview row.

DataTable must be set prior to using DataView

Hi i did look at search result for " DataTable must be set prior to using DataView." but none of their solutions fixed my problem or pointed me in the right direction.
Were am i going wrong here, when i press a header to sort out the gridview table i just get an error and no sorting. The error is the same as my title for this post.
EDIT: Not sure if its relevant but i populate the gridview on page load from a MS SQL database
Mark-up
<asp:GridView ID="_propertyGridView" runat="server" CssClass="table table-hover table-striped" AutoGenerateColumns="false" AllowSorting="true" GridLines="None" OnRowCommand="PropertyRowCommand" Width="100%">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Ref" SortExpression="Id" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="PostCode" HeaderText="Post Code" SortExpression="PostCode" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="ContractsFinishedOn" HeaderText="Contract Signed On" SortExpression="ContractsFinishedOn" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Mobile" HeaderText="Mobile No." SortExpression="Mobile" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="LandLordEmail" HeaderText="Owners Email" SortExpression="LandLordEmail" HeaderStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="MoveInDate" HeaderText="Move In Date" SortExpression="MoveInDate" HeaderStyle-HorizontalAlign="Left" />
<asp:TemplateField HeaderText="Status" SortExpression="Status1">
<ItemTemplate>
<asp:CheckBox ID="_tenantPaymentCheckBox" runat="server" Enabled="false" Checked='<%#Bind("TenantReceipt") %>' />
<asp:LinkButton ID="_tenantPaymentLink" Text="Send Tenant Receipt" CommandArgument='<%#Bind("Id") %>' CommandName="TenantEmail" runat="server" OnClientClick="javascript:return confirm('This will email & sms the tenant, please make sure its correct');" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" SortExpression="Status2">
<ItemTemplate>
<asp:CheckBox ID="_landlordInfoCheckBox" runat="server" Enabled="false" Checked='<%#Bind("LandlordInfo") %>' />
<asp:LinkButton ID="_landlordInfoLink" Text="Request Landlord Info" CommandArgument='<%#Bind("Id") %>' CommandName="LandlordInfoEmail" runat="server" OnClientClick="javascript:return confirm('This will email & sms the landlord, please make sure its correct');" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" SortExpression="Status3">
<ItemTemplate >
<asp:CheckBox ID="_landlordRentCheckBox" runat="server" Enabled="false" Checked='<%#Bind("LandlordReceipt") %>' />
<asp:LinkButton ID="_landlordRentLink" Text="Send Landlord Receipt" CommandArgument='<%#Bind("Id") %>' CommandName="LandlordEmail" runat="server" OnClientClick="javascript:return confirm('This will email & sms the landlord, please make sure its correct');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-Behind
protected void _propertyGridView_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
string sortExpression = e.SortExpression;
ViewState["z_sortexpresion"] = e.SortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, "DESC");
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, "ASC");
}
}
catch (Exception ex)
{
SearchErrorLbl.Text = "error in such";
}
}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set
{
ViewState["sortDirection"] = value;
}
}
private void SortGridView(string sortExpression, string direction)
{
DTSorting = new DataView(DTSorting, "", sortExpression + " " + direction, DataViewRowState.CurrentRows).ToTable();
_propertyGridView.DataSource = DTSorting;
_propertyGridView.DataBind();
}
public DataTable DTSorting
{
get
{
if (ViewState["Sorting"] != null)
return (DataTable)ViewState["Sorting"];
else
return null;
}
set
{
ViewState["Sorting"] = value;
}
}
Seems to me that the problem is within SortGridView method. You try to use the very same DTSorting property you attempt to set as the table constructor parameter. If it is null at this point it will most definitely throw an exception. DataView needs an existing DataTable instance to work with.
I should also mention that the current implementation will likely create multiple DataTable instances that won't ever get disposed of. One thing for sure is that you aren't disposing of the DataView object you are creating so that you get your sorted table.
If I were you I would rethink how data should be bound. Storing a DataTable object in ViewState is bad practice. The full table will be serialized back and forth between the client and the server, resulting in performance loss.
I suggest you read about it here: View State Overview

How to disable LinkButton within GridViewclick from Client Side using JavaScript?

I have a GridView, In one column I have LinkButton control. I want to disable click from client side for certain condition on this column. Means for some rows it will not be possible for User to call onclick event and for some rows it is possible.
I want to achieve this from client side using javascript.
Or When User clicks on link, It will notify the User that this action can't be completed for this row.
<asp:GridView Width="100%" ShowHeader="true" ViewStateMode="Enabled" GridLines="Both" CellPadding="10" CellSpacing="5" ID="GridViewMultiplePOSAssociationId" runat="server" AllowSorting="false" AutoGenerateColumns="false" OnRowCommand="RewardGridMultiD_RowCommand"
AllowPaging="true" PageSize="8" OnRowDataBound="grdViewCustomers_OnRowDataBound" PagerSettings-Position="Top" PagerSettings-Mode="NumericFirstLast" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" DataKeyNames="POS Id">
<RowStyle CssClass="table_inner_text" BackColor="WhiteSmoke" BorderColor="CornflowerBlue" Wrap="true" ForeColor="Black" Height="30px" />
<HeaderStyle CssClass="table_head_text" />
<Columns>
<asp:TemplateField ItemStyle-Width="80px">
<ItemTemplate>
<a href="JavaScript:divexpandcollapse('div<%# Eval(" POS Id ") %>');">
<img alt="Details" id="imgdiv<%# Eval("POS Id") %>" src="images/plus.png" />
</a>
<div id="div<%# Eval(" POS Id ") %>" style="display: none;">
<asp:GridView ID="grdViewOrdersOfCustomer" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<RowStyle CssClass="table_inner_text" BackColor="SkyBlue" BorderColor="Black" Wrap="true" ForeColor="White" Height="30px" />
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="RULE FILE NAME" HeaderText="RULE FILE NAME" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE ID" HeaderText="RULE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="RULE TYPE ID" HeaderText="RULE TYPE ID" />
<asp:BoundField ItemStyle-Width="150px" DataField="START TIME" HeaderText="START TIME" />
<asp:BoundField ItemStyle-Width="150px" DataField="EXPIRY TIME" HeaderText="EXPIRY TIME" />
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="Row Number">
<ItemTemplate>
<asp:Label ID="LabelRowNumberId" runat="server" Text='<%#Eval("Row Number") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="POS Id">
<ItemTemplate>
<asp:Label ID="LabelPOSID" runat="server" Text='<%#Eval("POS Id") %>'></asp:Label>
<%-- <asp:LinkButton ID="LinkbtnPOSId" CommandArgument='<%#Eval("POS Id") %>' CommandName="ClickPOS" Text='<%#Eval("POS Id") %>' runat="server" CausesValidation="false"></asp:LinkButton>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="HyperLinkAssociate" CommandArgument='<%#Eval("POS Id") %>' CommandName="Associate" Text="Associate" runat="server" OnClientClick="return OnClientClickAssociateRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>/
<asp:LinkButton ID="HyperLinkReplace" CommandArgument='<%#Eval("POS Id") %>' CommandName="Replace" Text="Replace" runat="server" OnClientClick="return OnClientClickReplaceRewardRuleFile(this);" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="250px" ItemStyle-HorizontalAlign="Center" HeaderText="Status">
<ItemTemplate>
<asp:Label runat="server" ID="LabelStatusPendingPOSId" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In GridViewMultiplePOSAssociationId there is one column "Status" which has label LabelStatusPendingPOSId, LabelStatusPendingPOSId text is set Applied, Not Applied at the time of Binding. For Rows which has Status Applied, User should not be able to click on LinkButton Associate/Replace else He is allowed to click.
use this code OnRowDataBound for Your Grid
protected void grdViewCustomers_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
LinkButton LinkbtnPOSId=(LinkButton)e.Row.FindControl("LinkbtnPOSId");
Label LabelStatusPendingPOSId = (Label)e.Row.FindControl("LabelStatusPendingPOSId");
Boolean boolStatus = LabelStatusPendingPOSId.Text == "Applied" ? true : false;
//LinkbtnPOSId.Attributes.Add("onclick", "function CheckStatus('" + boolStatus.ToString() + "')");
LinkbtnPOSId.Enabled = boolStatus;
}
}
Try this..
You can loop through the Gridview and make the particular control disable...
I am writing the code in javascript pageload function...
function PageLoad(sender, args)
{
for (var i = 0; i <= RowCount; i++)
{
document.getElementById('Gridview1_HyperLinkAssociate_' + i.toString() + '').disabled = true;
}
}
Set RowCount as the number of rows of the Gridview...

I would like to ask about double clicked the data Gridview row then the code below layout

HTML CODE, this concept can work , but i need to apply it on my gridview table after data binded.
$(document).ready(function () {
$('.clickme').click(function() {
alert("Hello World");
});
});
<tr class="clickme">
<td>Shop: </td>
</tr>
<asp:GridView ID="dgMain" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ChassisNo" OnPageIndexChanging="dgMain_PageIndexChanging"
OnRowCreated = "OnRowCreated" CssClass="table table-bordered" CellPadding="6" HeaderStyle-BackColor="#eeeeee" OnSorting="Sorting">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox id="chkSelection" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No" >
<ItemTemplate>
<asp:Label id="LabelNo" runat="server" >
<%# GetIndex( DataBinder.Eval(Container, "RowIndex")) %>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="OperationName" HeaderText="Operation Name" SortExpression="OperationName"/>
<asp:BoundField DataField="OperationStart" HeaderText="Operation Start" SortExpression="OperationStart"/>
<asp:BoundField DataField="LOTNo" HeaderText="LOT No" SortExpression="LOTNo"/>
<asp:BoundField DataField="MSC" HeaderText="MSC" SortExpression="MSC" />
<asp:BoundField DataField="MaterialGroup" HeaderText="Material Group" SortExpression="MaterialGroup"/>
<asp:BoundField DataField="ChassisNo" HeaderText="Chassis No" SortExpression="ChassisNo" />
<asp:BoundField DataField="ColorID" HeaderText="Color ID" SortExpression="ColorID"/>
</Columns>
<PagerStyle HorizontalAlign="Center" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView>
I would like to click on the row1 diagram below then will prompt out the message Hello world,
if i clicked on Row2 it will to display helloworld2.
__________________________________________________________________
|___Row1__________|_____Row1____|_______Row1_____|_____Row1________|
|___Row2__________|_____Row2____|_______Row2_____|_____Row2________|
|___Row3__________|_____Row3____|_______Row3_____|_____Row3________|
|___Row4__________|_____Row4____|_______Row4_____|_____Row4________|
If you wants to display just alert with rowNumber then it is so simple
Use
onrowdatabound="CustomersGridView_RowDataBound" for Your gridview
<asp:gridview id="CustomersGridView"
autogeneratecolumns="true"
allowpaging="true"
onrowdatabound="CustomersGridView_RowDataBound"
runat="server">
</asp:gridview>
and on Server Side
public void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "alert('helloworld " + e.Row.RowIndex + "')");
}
}

Categories

Resources