passing multivariables to new page via gridview select - c#

I have a gridview where i want to pass two different ID when i select a row to a new page.
I need them to be two different variables so i dont want to bind them together.
Currently, the way i am doing it with link select the values of SUBMITTEDJOBAPPLICATION & the
JOBAPPLICATIONID variables are the same(which is incorrect). What i mean is the SUBMITTEDJOBAPPLICATION is correct but the
JOBAPPLICATIONID is the same as SUBMITTEDJOBAPPLICATION and that is incorrect.
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/UnscreenedApplicantPage.aspx?SubmittedID={0}&jobID={0}", Eval("SUBMITTEDJOBAPPLICATION"), Eval("JOBAPPLICATIONID")) %>'>Select</asp:HyperLink>
How can i remedy this?

change SubmittedID={0}&jobID={0}
to
SubmittedID={0}&jobID={1}
in String.Format("SubmittedID={0}&jobID={0}", Eval("SUBMITTEDJOBAPPLICATION"), Eval("JOBAPPLICATIONID")) you only use zero index so fist parameter will replace both places.

You should try this
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/UnscreenedApplicantPage.aspx?SubmittedID={0}&jobID={1}", Eval("SUBMITTEDJOBAPPLICATION").ToString(), Eval("JOBAPPLICATIONID").ToString()) %>'>Select</asp:HyperLink>
You need Eval("SUBMITTEDJOBAPPLICATION").ToString(), Eval("JOBAPPLICATIONID").ToString() as well.

Related

Dynamically resolve a resource key

I would like to insert a string (key) into a '<%$ Resources:resFile, someKey %>' statement dynamically at runtime.
Right now I have this:
<asp:Label runat="server" id="lbl" Text='<%$ Resources:resFile, someKey %>'/>
which is useless to me, because the key "someKey" is static and will always converge to the same x translations.
I've tried doing things like this:
<asp:Label runat="server" id="lbl" Text='<%$ Resources:resFile, '<%#Eval("someProperty")%>' %>'/>
But this doesn't quite compile. I'm not sure if you can have nested <%%> statements, so thats why i'm asking here.
I've also tried a variety of things with GetGlobalResourceObject() but that doesn't do what i want either.
The thing is that i am binding a list to a repeater, and one of the items in the datasource will contain the key that will match a key in the resource files.
If anyone knows a way how to achieve this, be it with nested <%%> statements or be it any other way, i'd be happy to try it out.
You could do this in Code-Behind on the ItemDataBound Event.
Label lv = (Label)e.Item.FindControl("lbl");
ResourceManager resMngr = new ResourceManager(typeof(SupertextCommon.Default));
lv.Text = resMngr.GetObject(someProperty, culture);
This has worked for me in a GridView using a property of its datasource:
<%# GetGlobalResourceObject("Resource", Eval("SomeProperty").ToString()) %>
You can also use concatenation to build the key, e.g.:
<%# GetGlobalResourceObject("Resource", "SomePrefix" & Eval("SomeProperty").ToString()) %>

Surrounding Eval with html tags

Please please help!! I've been searching this for hours but maybe the solution is so obvious I'm completely overlooking it :(
I have a listview that binds to a sql table. The table contains a bunch of fields that hold only 'T' or NULL values, except for the last two fields which hold free-type text for user comments.
For the T/NULL values - The listview is configured so that an empty cell will not display, and where there is a 'T' value, it will instead show a custom text and create a line break for the next item. This syntax does exactly that:
<asp:Label ID="LymeLabel" runat="server" Text='<%# Eval("Lyme","Lyme Disease<br />") %>' />
However, I want the last two fields (the free-type text) do display in a paragraph style, with paragraph tags surrounding the Eval statement. The tags have to form part of the Eval so that they won't render whitespace if the cells are empty. My thinking was to do it this way but it doesn't work - the whitespace shows up either way:
<asp:Label ID="OtherCommentLabel" runat="server" Text='<%# "<p>"+Eval("OtherComment")+"</p>" %>' />
I'm guessing the " "+ ... +" " doesn't care what's in or not in the middle.. but how to fix it? There must be a very simple solution to this and I feel really stupid even asking this. Any advice please?
From the description, you don't need the asp:Label at all. Why not just wrap the Eval() in a P tag?
<p><%# Eval("Lyme","Lyme Disease") %></p>
Even if the label worked, you wouldn't want the resulting markup (paragraph inside a label makes no sense).
To handle the show/hide if the item is empty, you could do something like:
<ItemTemplate>
<p runat="server" visible='<%#!string.IsNullOrEmpty(Eval("OtherComment"))%>'>
<%# Eval("Lyme","Lyme Disease") %>
</p>
</ItemTemplate>
The white space will show up because p is not part of the Eval; <p>Eval()</p>.
Not sure if elegant, but you could wrap the Eval inside a method:
public string ParagraphIfData(string input)
{
if(!string.IsNullOrEmpty(input))
return "<p>" + input + "</p>";
return "";
}
Then:
<%# ParagraphIfData(Eval("Lyme","Lyme Disease")) %>

ASP.NET GridView bind two field into one column

I have ASP.NET GridView in my web app and would like to bind two fields into one column and use string formatting. I am providing example below, is it possible to implement into GridView?
I have two data fields Name and DefaultParam and would like to display these fields into one GridView column.
Like this
Name=DefaultParam
If DefaultParam value is empty I would like to show only Name value and do not include =
I was using Repeater and code below to achieve this but now decided to move data display to GridView
<%#Eval("Name")%>
<%# (!string.IsNullOrEmpty(Eval("DefaultParam").ToString())) ? "= " + Eval("DefaultParam"):"" %>
You can use a TemplateField and put your logic in there:
<asp:TemplateField HeaderText="Header">
<ItemTemplate>
<%#Eval("Name") + (!string.IsNullOrEmpty(Eval("DefaultParam").ToString())) ? "= " + Eval("DefaultParam"):""%>
</ItemTemplate>
</asp:TemplateField>
Another option would be to use a Property on your object to do that logic for you behind the scenes and just use that as a BoundField, but you didn't mention what the object is your binding is.
You can simple write server-side code between <%# ... %> as you write in code behind. just put it in '' (between single quotes) .
<asp:Lable id="lblxx" runat="server"
Text='<%# Eval("Name") + (!string.IsNullOrEmpty(Convert.ToString(Eval("DefaultParam")))) ? "= " + Eval("DefaultParam"):"" %>' />
Follow this tutorial link to know that how to Custom Formatting Based Upon Data using Template Fields.

Concat Two Bind Fields in DropDownList SelectedValue

I am trying to Concat to fields in the SelectedValye property of the Dropdownlist. I want to use Bind and not Eval. This is what I am using but it's not working. Is this possible to do?
<asp:DropDownList ID="RsmList" runat="server" DataSource="<%# ddRSM.DataSource %>" SelectedValue='<%# Bind("RSMLast") + '', '' + Bind("RSMFirst") %>'>
</asp:DropDownList>
Thanks!
I dont believe you can without using Eval because Bind translates actually to two separate method calls. You need to either use Eval() or do it before you databind. But - happy to be proven wrong : )
I don't think you need your DataSource inside binding tags -- I don't set this stuff up in markup, but I believe your reference should just be DataSource="ddRSM.DataSource".
You should also be able to set your SelectedValue property like so:
SelectedValue='<%# Bind("RSMLast") %>, <%# Bind("RSMFirst") %>'

List View, sent parameters to method

I have list view with multiple lines and in every line I have textbox where is number of items in cart and refresh button. So if someone change number of items and click on update, I wanna change it in cookie and db. Im using CommandArgument where 1 parameters is ID of row in table between tableProduct and tableCart and second i wanna sent current value of textbox, where is how many items user wanna buy, but i dont know how to add. Can u help me?
<asp:TextBox runat="server" id="countInCart" Text='<%# Eval("countInCart") %>' /><asp:ImageButton ID="ImageButton1" runat="server" ImageAlign="AbsBottom" ImageUrl="~/Static/Img/inp-order-refresh.png" OnCommand="updateClick" CommandArgument='<%# Eval("id") + ";" + **here i want add value of countInCart, but I dont know how** %>' />
you are looking for a way to update them in bulk. have a look at this; http://geekswithblogs.net/thanigai/archive/2009/05/21/bulk-insert-update-and-delete-with-asp.net-listview-control.aspx

Categories

Resources