I have coded this page
I need to pass the uniqueidentifier to another page, i have try these ways :
e.Row.Cells[1].Text = "<a href='Clientes.aspx?UserName='>" + e.Row.Cells[0].Text + "</a>";
and this
Response.Redirect("~/Clientes.aspx?Nome=" + e.Row.Cells[0].Text);
what the best and secure way to pass the GUID to another page ???
Thanks
Alejandro Carnero
In the codebehind of your first page, store the unique identifier in a Session variable, and then redirect to the "Clients" page normally:
Session["myUniqueID"] = e.Row.Cells[0].Text;
Response.Redirect("~/Clientes.aspx");
Then, in the codebehind of "Clientes.aspx", retreive it:
protected void Page_Load(object sender, EventArgs e)
{
string myUniqueID = Session["myUniqueID"].ToString();
}
Note: I use "Page_Load" as an example, you could put this code in whatever method you want.
I have solved this way , source page :
<tr>
<td colspan="3">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="False"
CellPadding="4" ForeColor="#333333" GridLines="None" Width="770px" >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField Text="Mostrar Cadastro" DataNavigateUrlFields="idcliente"
DataNavigateUrlFormatString="~/Clientes.aspx?ID={0}"
/>
<asp:BoundField DataField="idcliente" HeaderText="ID" />
<asp:BoundField DataField="nome" HeaderText="Nome" />
<asp:BoundField DataField="endere" HeaderText="Endereço" />
<asp:BoundField DataField="Tel" HeaderText="Telefone" />
<asp:BoundField DataField="pedido" HeaderText="Pedido" />
Destiny page :
protected void Page_Load(object sender, EventArgs e)
{
LblIDCliente.Text = Request.QueryString["ID"];
}
Related
I have used dx:ASPxGridView where I have one dx:GridViewDataTextColumn with EditItemTemplate which contain dx:ASPxListBox. When I click on update command I am not able to get selected items of dx:ASPxListBox under ASPxGridView_Updating.
<dx:ASPxGridView
ID="ASPxGridView"
runat="server"
AutoGenerateColumns="False"
DataSourceID="TradersDS"
KeyFieldName="TraderId">
<SettingsEditing Mode="PopupEditForm" PopupEditFormWidth="600px" />
<ClientSideEvents RowDblClick="function(s, e)
{
s.StartEditRow(e.visibleIndex);
}"
EndCallback="PrepareGridViewForNewDesing" Init="PrepareGridViewForNewDesing" />
<Columns>
....
<dx:GridViewDataTextColumn FieldName="CounterParty" VisibleIndex="3">
<EditItemTemplate>
<dx:ASPxListBox ID="lstCounterParty" runat="server" SelectionMode="CheckColumn" EnableSelectAll="true"
Width="285"
Height="300"
DataSourceID="CounterPartiesDS"
ValueField="ID"
ValueType="System.String"
TextField="Name">
<%-- <ClientSideEvents SelectedIndexChanged="function(s, e) {lbModels.PerformCallback('1');}" />--%>
</dx:ASPxListBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
...
</Columns>
</dx:ASPxGridView>
C# Code..
protected override void ASPxGridView_Updating(object sender, ASPxDataUpdatingEventArgs e)
{
var gridView = sender as ASPxGridView;
GridViewDataColumn list = gridView.Columns["CounterParty"] as GridViewDataColumn;
var counterPartyListBox = (ASPxListBox)gridView.FindEditRowCellTemplateControl(list, "lstCounterParty");
string selectedItemsAsString = string.Empty;
foreach (ListEditItem item in counterPartyListBox.SelectedItems)
selectedItemsAsString += item.Value + ";";
base.ASPxGridView_Updating(sender, e);
}
Here I always get count 0 of SelectedItems. On addition to this My devExpress control version are 9.3.3
What is wrong with this code any help , guidance really appreciated.
Make sure that you set the ASPxListBox.ValueType property to the corresponding .NET type that matches the type of the "ValueField" column.
May be, according to the (ValueField="ID"), the (ASPxListBox.ValueType) should be numeric? (System.Int32, etc.)
my .aspx design source code is
<asp:GridView ID="grdPaymentStatus" runat="server"
AutoGenerateColumns="false"
CssClass="table table-responsive table-striped table-bordered table-advance table-hover"
HeaderStyle-CssClass="ProjectStatusHeader"
OnRowDataBound="grdPaymentStatus_RowDataBound" >
<Columns>
<asp:BoundField DataField="instCount" HeaderText="Installments" HeaderStyle-BackColor="#dddddd" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="instPayment" HeaderText="Amount" HeaderStyle-BackColor="#dddddd" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="instWord" HeaderText="Words" HeaderStyle-BackColor="#dddddd" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="instPaymentMode" HeaderText="Payment Mode" HeaderStyle-BackColor="#dddddd" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="instPaymentdat" HeaderText="Payment Done On" HeaderStyle-BackColor="#dddddd" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="instIspaid" HeaderText="Payment Status" HeaderStyle-BackColor="#dddddd" HeaderStyle-Font-Bold="false" />
</Columns>
</asp:GridView>
.aspx.cs code is
protected void grdPaymentStatus_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[2].Text != "Paid")
{
Button sendRequestButton = new Button();
sendRequestButton.ID = "PaymentRequest" + Row.Cells[0].Text;
sendRequestButton.Text = "Send Request";
sendRequestButton.CssClass = "btn blue";
sendRequestButton.UseSubmitBehavior = false;
sendRequestButton.CausesValidation = false;
sendRequestButton.Click += new EventHandler(sendRequestButton_OnClick);
e.Row.Cells[2].Controls.Add(sendRequestButton);
}
}
}
protected void sendRequestButton_OnClick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(AckNo))
BindDetailsPayment(AckNo);
}
Data is binding at page load in (! isPostback) method and whenever i am trying to click on button added in gridview the button click event (sendRequestButton_OnClick) is not firing
please help me out
thanks in advance.....
Even though you bound it on row bound, you need to handle the event in RowCommand.
See the following link.
I have gridview with 4 columns; in column 1 I added a place holder and other 3 columns are boundfields. In column 1 I'm adding radio buttons dynamically using html code by which I am able to select only one radio button. It's working well, but the problem is I am unable to find the radio button control when a button outside of the gridview is clicked.
Please help, I've been stuck on this problem for 4 days.
Thank you in advance.
I used the following code
.aspx File
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="3" ForeColor="Black" GridLines="Vertical"
onrowdatabound="GridView1_RowDataBound"
>
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="FIRST NAME" DataField="FNAME"/>
<asp:BoundField HeaderText="LAST NAME" DataField="LNAME"/>
<asp:BoundField HeaderText="EMAIL" DataField="EMAIL"/>
<asp:BoundField HeaderText="AGE" DataField="AGE"/>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:Button ID="btnSave" Text="Save" runat="server" onclick="btnSave_Click1" />
</form>
Code Behind file
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex != -1 && e.Row.DataItem != null)
{
PlaceHolder holder = (PlaceHolder)e.Row.FindControl("ph");
RadioButton rb = new RadioButton();
rb.ID = "rbSelect";
holder.Controls.Add(rb);
}
}
protected void btnSave_Click1(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
PlaceHolder holder = (PlaceHolder)GridView1.Rows[i].Cells[0].FindControl("ph");
RadioButton rbtn = holder.FindControl("rb") as RadioButton;
if (rbtn.Checked == true)
{
Response.Write("<Script>alert('Radiocheck')</Script>");
}
}
}
It's not clear why you need to create dynamic RadioButtons at all. That makes all just more difficult without a benefit in this case(even if, a nested Repeater or GridView would be easier).
However,
you should not create dynamic controls in RowDataBound since that is triggered only if the GridView was databound. But since by default ViewState is enabled you wouldn't DataBind it on postbacks. Dynamic controls on the other hand must be recreated on every postback.
Therefore create them in RowCreated which is triggered on every postback. But note that you have (of course) no DataItem there since it is null at this stage(even if the grid will be databound).
So you should create cynamic controls in RowCreated but load them from RowDataBound where you can also access them (f.e. via FindControl).
But instead of adding html-control like <input type='radio' you should create and add a RadioButton with an id. Otherwise you won't be able to acess it later, so holder.FindControl("rb") will, be null since it's not a server-control.
Here's the complete modified code:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
PlaceHolder holder = (PlaceHolder)e.Row.FindControl("ph");
var rb = new RadioButton();
rb.ID = "RbSample";
rb.Text = "rb";
holder.Controls.Add(rb);
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var row = ((DataRowView)e.Row.DataItem).Row;
var rb = (RadioButton)e.Row.FindControl("RbSample");
rb.Checked = row.Field<bool>("SampleActive");
}
}
protected void btnSave_Click1(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButton rbtn = (RadioButton)GridView1.Rows[i].FindControl("RbSample");
if (rbtn.Checked)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Radiocheck');", true);
}
}
}
It looks like you are doing FindControl with the "value" of the input, but not with the ASP.NET ID of the control, because it has none. Because it's not an ASP.NET control you cannot find it with FindControl.
I also don't know if you can loop through the Controls property of holder, because it's a plain html control. But you can try it out to put a breakpoint on the FindControl line and explore the Controls property of holder.
I have a grid view with below markup and below datasourse (linq query-stored procedure), I have added delete and update command field, but I do not know what code I have to add until deleting and updating for this grid view works.
<asp:GridView ID="GridViewDocuments_Search" runat="server" AutoGenerateColumns=False Visible="False" onrowcommand="GridViewDocuments_Search_RowCommand"
DataKeyNames="DocID" PageSize="100" >
<Columns>
<asp:TemplateField HeaderText = "Details">
<ItemTemplate>
<asp:Button ID ="btn_Show" Text="Details" runat= "server" CommandName= "Details" CommandArgument='<%#
Container.DataItemIndex%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="Docid,Transid"
DataNavigateUrlFormatString="~/DocResult.aspx?Docid={0}&TransID={1}"
DataTextField="DocumentNo" HeaderText="Doc" />
<asp:BoundField DataField="title" HeaderText="Title" SortExpression="title" />
<asp:BoundField DataField="transmittal" HeaderText="transmittal" SortExpression="transmittal" />
<asp:BoundField DataField="Docid" HeaderText="Docid" Visible="false" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
protected void btnSearch_Click(object sender, EventArgs e)
{
_DataContext = new EDMSDataContext();
var query = _DataContext.spQuickSearch(txtSearchKeywords.Text);
GridViewDocuments.Visible = false;
GridViewDocuments_Search.Visible = true;
GridViewDocuments_Search.DataSource = query;
GridViewDocuments_Search.DataBind();
}
The stored procedure spQuickSearch is like below:
ALTER proc [dbo].[spQuickSearch]
#Searchtext varchar(50)=null
AS
select DocId,TransId,DocumentNo,Title,TRANSMITTAL
from DocumentSum2
where DocumentNo like '%'+#SearchText + '%'
or Title like '%'+#SearchText + '%'
or TRANSMITTAL like '%'+#SearchText + '%'
You can handle commands like this:
protected void GridViewDocuments_Search_RowCommand(object sender, GridViewCommandEventArgs e)
{
string cmdArg = e.CommandArgument.ToString();
switch (e.CommandName)
{
case "Details":
//TODO: handle your Details command...
break;
case "Delete":
//TODO: handle your Delete command...
break;
}
}
You can add as many commands as you want (CommandName property for control). For example you can add another button and set Delete CommandName like this:
<asp:Button ID ="btn_Delete" Text="Delete" runat= "server" CommandName= "Delete" CommandArgument='<%#
Container.DataItemIndex%>' />
After command is completed you can call DataBind to refresh grid:
GridViewDocuments_Search.DataBind();
check this example
http://www.vkinfotek.com/gridview/gridview-commandfield.html
for detail
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.commandfield.showeditbutton.aspx
I want to take advantage of the breadth of attributes available to a LinkButton compared to a CommandField. When calling the code behind method from on click I get this error message:
CS0123: No overload for 'ViewHandler' matches delegate
'System.EventHandler'.
GridView definition:
<asp:GridView ID="wc" EmptyDataText="Empty WC table..." runat="server"
AutoGenerateColumns="False" GridLines="Horizontal" DataKeyNames="WC_ID,PW_ID,R_Qty"
CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
AllowSorting="true" OnSorting="Sorting" AllowPaging="true" PageSize="15" ViewStateMode="Enabled"
OnSelectedIndexChanging="ViewHandler" OnPageIndexChanging="HandlePageIndexChanging" OnRowDataBound="gvRowDataBound"
OnRowEditing="gvRowEditing" OnRowCancelingEdit="gvRowCancelingEdit" OnRowUpdating="gvRowUpdating">
Orig button...
<asp:CommandField ControlStyle-Font-Size="Smaller" ControlStyle-ForeColor="#717171" HeaderText="..." ShowSelectButton="True" ItemStyle-HorizontalAlign="Center" SelectText="..." />
Convert to....
<asp:TemplateField HeaderText="..." ShowHeader="True" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton style="font-size: 0.9em; color: #717171" ID="Details" runat="server" CausesValidation="False" OnClick="ViewHandler" CommandName="ViewHandler" Text="..." ToolTip="Click here to see purchase history and notes"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
Code behind:
protected void ViewHandler(object sender, GridViewSelectEventArgs e)
{
string WC_ID =wc.Rows[e.NewSelectedIndex].Cells[0].Text;
string PW_ID = wc.Rows[e.NewSelectedIndex].Cells[1].Text;
string VIN = wc.Rows[e.NewSelectedIndex].Cells[2].Text;
string PROD = wc.Rows[e.NewSelectedIndex].Cells[3].Text;
string W = wc.Rows[e.NewSelectedIndex].Cells[4].Text;
string SIZE = wc.Rows[e.NewSelectedIndex].Cells[5].Text;
e.Cancel = true;
Session.Add(WebConstants.WC_ID, WC_ID);
Session.Add(WebConstants.PW_ID, PW_ID);
Session.Add(WebConstants.VIN, VIN);
Session.Add(WebConstants.PROD, PROD);
Session.Add(WebConstants.W, W);
Session.Add(WebConstants.SIZE, SIZE);
DetailsNavigateMethod.DynamicInvoke();
HandlePageNavigation(WebConstants.WC_DETAILS, "WC View for WC_PurchaseID-> " + Session[WebConstants.WC_ID].ToString());
}
What do I need to do to make the signature match with the ViewHandler method? I did notice if I switch from GridViewSelectEventArgs to EventArgs the overload error goes away but then e.NewSelectedIndex does not exists...
Thanks!
Your problem is that the OnClick event handler for a LinkButton must have this signature:
protected void LinkButton_Click(Object sender, EventArgs e)
But you are defining it as
protected void ViewHandler(object sender, GridViewSelectEventArgs e)
However, you won't have access to e.NewSelectedIndex, obviously. What you can do is change your markup to (notice the CommandArgument part):
<asp:TemplateField HeaderText="..." ShowHeader="True" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton style="font-size: 0.9em; color: #717171" ID="Details" runat="server" CausesValidation="False" OnClick="ViewHandler" CommandName="ViewHandler" CommandArgument='<%=string.Format("{0},{1},{2},{3}",Eval("Prop1"),Eval("Prop2"),Eval("Prop3"),Eval("Prop4")) %>' Text="..." ToolTip="Click here to see purchase history and notes"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
And your code to:
protected void LinkButton_Click(Object sender, EventArgs e)
{
string [] values = ((LinkButton)(sender)).CommandArgument.Split(new char[]{','});
//where values[0] will have WC_ID, values[1]=PW_ID, etc,
Session.Add(WebConstants.WC_ID, values[0]);
Session.Add(WebConstants.PW_ID, values[1]);//etc...
//Session.Add(WebConstants.VIN, VIN);
//Session.Add(WebConstants.PROD, PROD);
//Session.Add(WebConstants.W, W);
//Session.Add(WebConstants.SIZE, SIZE);
DetailsNavigateMethod.DynamicInvoke();
HandlePageNavigation(WebConstants.WC_DETAILS, "WC View for WC_PurchaseID-> " + Session[WebConstants.WC_ID].ToString());
}
Note:
Prop1, Prop2, etc. have to be changed to actual property names from your data source.
Above code hasn't been tested but that's the idea.