protected void gvRequest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
bm.DeleteBookRequest(Convert.ToInt32(e.CommandArgument));
GetBooks();
GetRequest();
}
}
<asp:GridView ID="gvBooks" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"
BorderStyle="None" OnRowCommand="gvBooks_RowCommand" CssClass="gvBooks" CellPadding="5"
CellSpacing="7" ForeColor="Blue" OnRowDeleting="gvBooks_RowDeleting">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Select" CommandArgument='<%# Eval("Title") %>' runat="server"
ID="lb_Id">Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" CommandArgument='<%# Eval("Title") %>' runat="server"
ID="lb_Title">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:GridView ID="gvReviews" runat="server" AutoGenerateColumns="false" OnRowCommand="gvReviews_RowCommand"
OnRowDeleting="gvReviews_RowDeleting" CellPadding="5" CellSpacing="7" ForeColor="Blue">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Subject" HeaderText="Subject" />
<asp:BoundField DataField="Username" HeaderText="Username" />
<asp:BoundField DataField="Review" HeaderText="Review" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" CommandArgument='<%# Eval("Id") %>' runat="server"
ID="lb_IdDel">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:GridView ID="gvRequest" runat="server" onrowcommand="gvRequest_RowCommand" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblUsername" runat="server" Text='<%# Eval("Username") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" CommandName="Delete" CommandArgument='<%# Eval("id") %>' runat="server" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
when I click on the delete linkbutton the output is a blank page.
The view source after the click button is clicked is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<SCRIPT type=text/javascript src="http://www.google-analytics.com/ga.js"
async="true"></SCRIPT>
<SCRIPT type=text/javascript src="http://sg.perion.com/v1.1/js/gt.js"
async="true" onload="null"></SCRIPT>
</HEAD>
<BODY></BODY></HTML>
internal void DeleteBookRequest(int id)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Delete from bookrequest where id=#id";
cmd.Parameters.Add("#id", SqlDbType.BigInt, 19, "id").Value = id;
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
}
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 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 have a gridview
<asp:GridView ID="wbsdataGV1" runat="server" Width="790px" AutoGenerateColumns="False"
OnSelectedIndexChanged="wbsdataGV1_SelectionChanged" DataKeyNames="WBSCode">
<Columns>
<asp:TemplateField HeaderText="WBS Code">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("WBSCode") %>'></asp:LinkButton>
</ItemTemplate>
<ControlStyle Width="100px" />
<ItemStyle BorderStyle="Solid" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:TextBox ID="TextBox40" runat="server" Text='<%# Eval("Description") %>' ReadOnly="true"
Width="300px">
</asp:TextBox>
</ItemTemplate>
<ControlStyle Width="300px" />
<ItemStyle BorderStyle="Solid" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Territory Code">
<ItemTemplate>
<asp:Label ID="Label45" runat="server" Text='<%# Eval("TerritoryCode") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="100px" />
<ItemStyle BorderStyle="Solid" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:Label ID="Label46" runat="server" Text='<%# Eval("AmountReleased") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="100px" />
<ItemStyle BorderStyle="Solid" BorderWidth="1px" />
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Wheat" BorderStyle="Solid" BorderWidth="1px" />
<RowStyle BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
</asp:GridView>
now in the link button i want to click it and retrieve that row's data in the same page and show it...
i am using
protected void wbsdataGV1_SelectionChanged(object sender, EventArgs e)
{
string rowID = (string)this.wbsdataGV1.SelectedDataKey.Value;
con.Open();
SqlCommand cmd = new SqlCommand(" select WBSCode,Description,TerritoryCode,AmountReleased from WBS where WBSCode='"+rowID+"'");
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
wbssearchdata1.DataSource = dt;
wbssearchdata1.DataBind();
}
con.Close();
}
this code but its not firing on the click .. so how can i solve this.. any help?
From your code I couldn't see anywhere you specified the button that fires the SelectedIndexChanged event. You'll need to do these
<asp:GridView OnSelectedIndexChanged="wbsdataGV1_SelectionChanged"
AutoGenerateSelectButton="true" />
Or
<asp:GridView OnSelectedIndexChanged="wbsdataGV1_SelectionChanged">
<Columns>
<asp:CommandField ShowSelectButton="true" />
</Columns>
</asp:GridView>
Or
<asp:GridView OnSelectedIndexChanged="wbsdataGV1_SelectionChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="Selecting" CommandName="Select" Text="Select Row"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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 .