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...
Related
I have a simple gridview with button for each row, and I want to pass or display the value of user_full_name_ar in a label, I tried doing this using javascript function as shown below but it doesn't show the data it shows null,
gridview code:
<asp:Label ID="Label5" Text='transfer text here' runat ="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="user_name" DataSourceID="SqlDataSource1" Height="100px" Width="383px">
<Columns>
<asp:BoundField DataField="user_name" HeaderText="user_name" ReadOnly="True" SortExpression="user_name" />
<asp:BoundField DataField="user_full_name_ar" HeaderText="user_full_name_ar" SortExpression="user_full_name_ar" />
<asp:TemplateField HeaderText="user_full_name_ar" SortExpression="user_full_name_ar">
<ItemTemplate>
<asp:Label ID="Label4" Text='<%# Session["lang"].ToString() == "en"? Eval("user_full_name_en") : Eval("user_full_name_ar") %>' runat ="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="ButtonSearch" runat="server" text="select" OnClientClick ="txt();" CommandArgument ='<%# Bind("user_name") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
javascript function to display value of label4 in gridview to label5 outside gridview :
<script type ="text/javascript" >
function txt() {
var t = document.getElementById("Label4");
document.getElementById("Label5") = t.value;
}
</script>
you can use a CommandField in gridview
<asp:Label ID="Label5" Text='transfer text here' runat ="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="user_name" DataSourceID="SqlDataSource1" Height="100px" Width="383px">
<Columns>
<asp:CommandField HeaderText="select" SelectText="select " ShowSelectButton="True">
</asp:CommandField>
<asp:BoundField DataField="user_name" HeaderText="user_name" ReadOnly="True" SortExpression="user_name" />
<asp:BoundField DataField="user_full_name_ar" HeaderText="user_full_name_ar" SortExpression="user_full_name_ar" />
<asp:TemplateField HeaderText="user_full_name_ar" SortExpression="user_full_name_ar">
<ItemTemplate>
<asp:Label ID="Label4" Text='<%# Session["lang"].ToString() == "en"? Eval("user_full_name_en") : Eval("user_full_name_ar") %>' runat ="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="ButtonSearch" runat="server" text="select" OnClientClick ="txt();" CommandArgument ='<%# Bind("user_name") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
after in selectedindexchenge event write code below
Label5.Text = GridView1.SelectedRow.Cells[2].Text;
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?
I'm displaying information in a Datagrid not gridView in asp.net. the datagrid contain a column called Status. the status can either be 1 or -1. if the status is 1, i'm displaying a mark icon, then if the status is -1 then displayed a cancel icon. i have done the coding and its working but the problem is, the icons are not showing in all the column depending on the condition as shown in the image below. based on the value in my databasee, the status columns are all -1 but if its showing, its skip on column and bind the next column and so on.
here is my DataGrid Markup
<asp:DataGrid ID="VehicleInfo" runat ="server" AutoGenerateColumns="False" GridLines="Horizontal" Width="939px" CssClass=" table table-striped table-bordered" AllowCustomPaging="True" AllowPaging="True" PageSize="50" OnItemDataBound="VehicleInfo_ItemDataBound" OnItemCommand="VehicleInfo_ItemCommand" >
<Columns>
<asp:TemplateColumn HeaderText="#" >
<ItemTemplate>
<%# Container.DataSetIndex + 1 %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Type" HeaderText="Veh. Type"></asp:BoundColumn>
<asp:BoundColumn DataField="Make" HeaderText="Make/Model"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Veh. Reg No">
<ItemTemplate>
<asp:Label ID="RegNo" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.RegistrationNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="EngineNumber" HeaderText="Engine No"></asp:BoundColumn>
<asp:BoundColumn DataField="ChasisNo" HeaderText="Chasis No"></asp:BoundColumn>
<asp:BoundColumn DataField="InjectionYear" HeaderText="Injection Year"></asp:BoundColumn>
<asp:BoundColumn DataField="Size" HeaderText="Veh. Size"></asp:BoundColumn>
<asp:BoundColumn DataField="ServiceTypeName" HeaderText="Service Type"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Response Status">
<ItemTemplate>
<asp:Label ID="Status" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.registrationstatusResponse") %>'></asp:Label>
<asp:ImageButton ID="cancel" Width="30" Height="30" ImageUrl="/images/cancel.png" Runat=server Visible="false" />
<asp:ImageButton ID="good" Width="30" Height="30" ImageUrl="/images/good.png" Runat=server Visible="false" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="verificationComment" HeaderText="Remark"></asp:BoundColumn>
</Columns>
<HeaderStyle Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small" CssClass="" ForeColor="White" BackColor="#428BCA" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
<ItemStyle Font-Names="Verdana" Font-Size="X-Small" />
</asp:DataGrid>
and here is my code on the itemDataBound event and i Even try using a loop on the ItemDataBound event but it doesn't work. Please i need your help if there is anything im missing.
protected void VehicleInfo_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item))
{
var lab1 = (Label)e.Item.FindControl("status");
var img1 = (ImageButton)e.Item.FindControl("good");
var img2 = (ImageButton)e.Item.FindControl("cancel");
if (lab1.Text == "1")
{
img2.Visible = false;
img1.Visible = true;
}
else if (lab1.Text == "-1")
{
img2.Visible = true;
img1.Visible = false;
}
}
}
I have a expand collapse nested grid view like below.
The childgrid (gvChild) column is a linkbutton column on the click of which I need to get the name of the city which was clicked. My rowcommand event to capture that on the child gridview is like this:
protected void gvChild_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ShowDetails")
{
int index = Convert.ToInt32(e.CommandArgument);
GridView gridChild = (GridView)gvwParent.Rows[index].FindControl("gvChild");
foreach (GridViewRow row in gridChild .Rows)
{
string aCity= ((LinkButton)row.Cells[1].FindControl("lnkSelectedCity")).Text;
}
}
}
I understand the findcontrol line is def wrong, but how else would I do the findcontrol of the child grid to get the right link button that was clicked? Right now if I select "London", the Index value is 1 and the String "aCity" is taking it as "Utah". Will appreciate inputs on this. Thank you.
Code on my aspx page:
<asp:GridView ID="gvParent" runat="server"
AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="CountryID"
OnRowDataBound="gvParent_RowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href="javaScript:divexpandcollapse('div<%# Eval("CountryID") %>');">
<img id='imgdiv<%# Eval("CountryID") %>' width="9px" border="0" src="expand_white.gif"
alt="" /></a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CountryDesc">
<ItemTemplate>
<asp:Label ID="lblEmpID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CountryDesc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id='div<%# Eval("CountryID") %>' style="display: none; position: relative; left: 15px; overflow: auto">
<asp:GridView ID="gvChild" runat="server" AutoGenerateColumns="False" PageSize="5"
Width="100%" Height="270px" ShowHeader="False" OnRowDataBound="gvChild_RowDataBound">
<Columns>
<asp:BoundField DataField="CityID" HeaderText="CityID">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelectedCity" runat="server" Text='<% # Eval("CityName") %>'
CommandName="ShowDetails" CommandArgument='<%# Container.DataItemIndex %>' ToolTip="Select x"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Assigned" HeaderText="Assigned">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="CountryID" HeaderText="Assigned">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="ClassID" HeaderText="ClassID">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="UOM" HeaderText="UOM">
<HeaderStyle CssClass="Invisible" />
<ItemStyle CssClass="Invisible" HorizontalAlign="Left" />
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
</td></tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I assume CityID is a unique key. If so, you can assign CityID to CommandArgument.
Then you can retrieve the CityID back from CommandArgument after post back.
<asp:GridView ID="gvChild" ... DataKeyNames="CityID">
<Columns>
...
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkSelectedCity"
...
CommandArgument='<%# Eval("CityID") %>'
ToolTip="Select x" />
</ItemTemplate>
</asp:TemplateField>
protected void gvChild_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ShowDetails")
{
int cityId = Convert.ToInt32(e.CommandArgument);
}
}
I am trying to pass RegionProjectID column of my grid from query string when ever a user will click on the RegionProjectName field on the grid. I had made RegionProjectname as hyperlink and below you can find the Code also. But this is not working . Please suggest me or help that why it is not working. The pagin is also enabled in my grid view.
<asp:GridView ID="ResultGridView" runat="server" AutoGenerateColumns="False" ShowFooter="true"
DataKeyNames="RegionProjectID"
AllowPaging="True"
CellPadding="3"
OnPageIndexChanging="ResultGridView_PageIndexChanging"
OnRowDeleting="ResultGridView_RowDeleting"
CssClass="mGrid"
OnRowEditing="ResultGridView_RowEditing"
OnRowUpdating="ResultGridView_RowUpdating"
OnRowCancelingEdit="ResultGridView_RowCancelingEdit"
PageSize="15" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellSpacing="2"
OnRowCommand="ResultGridView_RowCommand" >
<Columns>
<asp:BoundField DataField="RegionProjectID" HeaderText="Region ID" InsertVisible="False"
ReadOnly="True" SortExpression="RegionProjectID" Visible="false" />
<asp:TemplateField HeaderText="Region Name" SortExpression="RegionProjectName">
<EditItemTemplate>
<asp:TextBox ID="txtRegion" Width="250px" runat="server" Text='<%# Bind("RegionProjectName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtRegion1" runat="server" Width="250px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" CommandName="Details" CommandArgument='<%# Eval("RegionProjectID") %>' Text='<%# Bind("RegionProjectName") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="AddNew" Text="Add New"></asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
<%-- <asp:CommandField HeaderText="Select" ShowSelectButton="True" ShowHeader="True"/> --%>
</Columns>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<%--<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />--%>
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>`
protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Details")
{
Server.Transfer("Default3.aspx?ID=" + e.CommandArgument.ToString());
}
if (e.CommandName.Equals("AddNew"))
{
TextBox txtRegion1 = (TextBox)ResultGridView.FooterRow.FindControl("txtRegion1");
TextBox txtNatureOFWork1 = (TextBox)ResultGridView.FooterRow.FindControl("txtNatureOFWork1");
if (txtRegion1.Text != "")
{
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO RegionAndProjectInfo(RegionProjectName, NatureOFWorkID ) Values('" + txtRegion1.Text + "', '" + ddlnatureOfWork.SelectedValue.ToString() + "')";
conn.Open();
cmd.ExecuteNonQuery();
}
FillVendorGrid();
conn.Close();
}
}
You must use
Response.Redirect("Default3.aspx?ID=" + e.CommandArgument.ToString());
instead of Server Transfer, cause Server Transfer does a different thing compared to Response.Redirect.
The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as
`Server.Transfer("Default3.aspx?ID=" + e.CommandArgument.ToString()`, True);
, the existing query string and any form variables will still be available to the page you are transferring to.
its more of a file transfer, instead of a redirect
http://msdn.microsoft.com/en-us/library/ms525800%28v=vs.90%29.aspx
<ItemTemplate>
<asp:hyperlink id="LinkButton3" navigateurl='<%# "Default3.aspx?ID=" + Eval("RegionProjectID")%>' text='<%# Bind("RegionProjectName")%>' runat="server" />
</ItemTemplate>
I had updated the itemtemplate of Regionprojectname as above and now getting query string .