passing dynamic values for each row in listview - c#

i am using a list view for viewing some information to user there i used a hyperlink in each row to show detailed information in a modal popup in the same page what i want on the click of particular hyperlink the detailed report of that row only should display.
[ID] is the primary key in my database iam passing that as an object from aspx file to the code behind and using that id to fetch data from database.
but each time it is showing same information.

<asp:HyperLink ID="hlnkShow" runat="server" CssClass="showButton" OnClick='<%# Attach(Eval("ID")) %>' Text="Show" ToolTip="View the contents of the message"> </asp:HyperLink>
in the code behind in the attach function
protected string Attach(object ObjectID)
{
return ("return showComments($(this),'" + ObjectID + "');");
}
in the aspx again in the javascript
function showComments($element, objectID)
{
$('input[type=hidden][id$=hfObjectID]').val(objectID);
}
and using this hiddenfield value iam making a ajax call and the problem is solved

Related

Hyperlink onclick in RadGrid

So, I have a Radgrid and multiple controls in it. One of the functionality is to open a PDF once you click on a hyperlink and at the same time insert that clicked value in the database.
I was successful to open a PDF but I am not sure how do I insert this value in the db as I have already used "OnClick" event to open popup window for PDF. Can somebody please guide me in the right way? I have a method with a parameter that inserts the value but how do I call this method when clicked on the hyperlink?
<telerik:GridTemplateColumn UniqueName="GenerateAOC">
<ItemTemplate>
<asp:HyperLink ID="hlGenerateAOC" datanavigateurlfields="ShipmentNumber" Target="AOPLetter" runat="server" DatatextField="ShipmentNumber" Text="GenerateAOC" NavigateUrl='<%# "AdHocAOC.aspx?ShipmentNumber="+Eval("ShipmentNumber")%>' onclick="window.open (this.href, 'AOPLetter', 'height=700,width=700,scrollbars');">
</asp:HyperLink>
</ItemTemplate>
</telerik:GridTemplateColumn>
Try using asp.net LinkButton OnClientClick method to open pdf file and then server side OnCommand handler to save data in database. You can pass arguments e.g. Shipment number of the clicked row using CommandArgument
<asp:LinkButton runat="server" OnClientClick="window.open('<%#AdHocAOC.aspx?ShipmentNumber="+ Eval("ShipmentNumber")%>'); return true;" OnCommand="LinkButton_Command" CommandArgument="<%Eval("ShipmentNumber")%>" CommandName="SavePdfClickDetails" />
On server-side
void LinkButton_Command(Object sender, CommandEventArgs e)
{
//Here you can save data
if(e.CommandName == "SavePdfClickDetails") {
string shipmentNumber = e.CommandArgument;
}
}
Check http://www.dotnetbull.com/2013/05/how-to-handle-click-event-of-linkbutton.html

google map parameter not showing

I have textbox in asp.net where i am writting Address.
On linkbutton below i wanted to direct it to goole map.
I have below textbox:
<asp:TextBox ID="txtJobAddress" runat="server" TextMode="MultiLine" Width="95%" Height="20px"
onBlur="javascript:saveChanges('JobAddress');"></asp:TextBox>
Linkbutton as below:
<a href="http://maps.google.com/maps?q=<%=txtJobAddress.Text%>" target="_blank">
<img src="images/gmap_button.gif" alt="Map" />
</a>
but when its getting directed through anchor tag, its not catching "q" parameter.
Its giving as:
https://www.google.com/maps/preview?q=
why its not taking value of:
<%=txtJobAddress.Text%>
Please help me , how can i attach textbox string here in
http://maps.google.com/maps?q=<%=txtJobAddress.Text%>
as below
http://maps.google.com/maps?q=NewYork
The <%=txtJobAddress.Text%> will be empty on page load. Presumably your saveChanges method prompts an ajax call to save the "JobAddress"? If this is the case then a full page postback won't occur, and therefore the <%=txtJobAddress.Text%> isn't populated with the updated value as this would occur on the server. You'll want to populate the query string value client side
e.g. in your blur event you could add a call to a javascript function that updates your link:
onBlur="javascript:saveChanges('JobAddress'); updateLink()"
in your updateLink function you would update the link query string value

FindControl TextBox which don't get the good value Sharepoint

In my asp page i got :
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<asp:DropDownList ID="_SCP_ddlStatutDelais" runat="server"></asp:DropDownList>
<asp:TextBox ID="_SCP_tbTypeMiseProduction" Rows="3" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="_btSend" runat="server" Text="Envoyer" CssClass="ms-ButtonHeightWidth"
onclick="_btSend_Click"/>
</asp:Content>
Then, in my code behind, i get values from database to provide my TextBox and DDL in my Page_Load, and it works.
Then, i want to update my database with values modify by user, so i try to get the Text in TextBox but i can only got the Text that i put from my database, and myTextBox.Text ignore Text modify by user.
Code Behind :
protected void _btSend_Click(object sender, EventArgs e)
{
Control context = this.Page.Master.FindControl("PlaceHolderMain");
//Informations Database Connection etc...
reflector.Set(d[fieldtomap],rootTypeDescriptor, ref instance, ((TextBox)(context.FindControl(nodeName))).Text);
//Submit update to database
}
For example if i get from my database : "Test", i put in my TextBox "Test". Then user modify this value then validate with the button, ((TextBox)(context.FindControl(nodeName))).Text contains always "Test" and ignore user's modification.
Are you checking for Page.IsPostback when binding your data? You should only be binding on the initial page load, else, the change are overwritten - just like you are experiencing.

Pass data via hyperlink in gridview

I would like to pass data from a database column to another page via a hyperlink in the gridview, the data i want to pass is just a load of text. this is the code i have
<asp:HyperLinkField DataTextField="FullText"
DataTextFormatString="View Text" NavigateUrl="~/Abstract.aspx"
Target="_blank" />
This appears to work as far as opening up the correct page, but im unsure as to how to view the text on the new page, most help topics tell you how to pass the data to a new grid view, but i would just like to view the data within the page or a box or whatever will work.
Thanks
If my understanding is correct you just want to display the text passed as a query string to the new page, if this is correct, just read the query string and display it in a label.
In order for this to work, you need to specify the query string in the link inside your grid, your link would have to look something like;
~/Abstract.aspx?d=your+text
In your datagrid:
<asp:TemplateColumn>
<ItemTemplate>
<asp:HyperLink
NavigateUrl='<%# "~/Abstract.aspx?d=" + HttpUtility.UrlEncode(DataBinder.Eval(Container, "DataItem.Id").ToString()) %>'
runat="server"
Text="Product" />
</ItemTemplate>
</asp:TemplateColumn>
In the target page you would have something like:
string text = string.Empty;
if (this.Request.QueryString["d"] == null)
text = "Not found";
else
text = Server.UrlDecode(this.Request.QueryString["d"]);
// encode the text to avoid XSS (cross-site scripting)
this.myLabel.Text = Server.HtmlEncode(text);
On the grid
<asp:HyperLinkField DataTextField="FullText"
DataTextFormatString="View Text"
NavigateUrl='<%# "~/Abstract.aspx?ft=" + System.Web.HttpUtility.UrlEncode(Eval("FullText").ToString() %>'
Target="_blank" />
On the page you want to read the param you would have
string fullText = Request.QueryString["ft"];
if (string.IsNullOrEmpty(fullText))
{
fullText = HttpUtility.UrlDecode(fullText);
}
You might want to pass a key parameter through querystring to pull data you want to view.
If that is not what you want please make your question more explanatory.
You can pass ID in session or in query string (Abstract.aspx?textid=1). Read this id in page load event get data from database and display.

How to select a row from grid view and edit the details in a new webform using ASP.NET

I have displayed some fields in grid view, Now i want to select a row and i want to display all field from sql server in to a web form, after displaying the data in respective controls(textbox, dropdown), i want to update it.
How i can redirect the page to new webpage after selecting the respective row from grid view (Using primary key). and how the data will be pass on page load in respective fields so i could able to update it by using update query.
As i new to ASP. Net. Please update me in detail. If possible please with code.
It would go something like this.
You will make a 'list' webform with all records containing the gridview
Make another webform called details
The gridview on list page will contain a hyperlink button field something like this
<asp:HyperLinkField Text="View Details" DataNavigateUrlFields="YourId" DataNavigateUrlFormatString="details.aspx?id={0}" />
(Notice I am just redirecting to the details page passing the field id with querystring.
Now, on details page you would just fetch the querystring value & query your database with a datareader & populate your details page.
Something like on page load
if(Request.QueryString["id"])!=null)
{
// Fetch respective item from database here & populate form fields
// Open connection(); execute datareader;populate form fields
}
Easiest way to do this:
<asp:GridView ID="grd" runat="server" autogeneratedcolumn="false">
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%#Eval("ID")%>
<ItemTemplate>
<asp:TemplateField>
<asp:TemplateField HaderText="Edit">
<ItemTemplate>
<a href='EditData.aspx?ID=<%#Eval("ID")%>'>Edit</a>
</ItemTemplate>
<asp:TemplateField>
<asp:GridView>
EditData.aspx page will be used to edit the data. After receiving the Query-string Value,we can bind the data to the controls and then update the data after making changes.

Categories