ASP.Net Mailto link not working - c#

I am trying to open a mailto that will use the emailaddress from the databound field and add a custom subject line and custom body.
My mailto window pops up and the email address specific to the data field is populated, however the subject and the body remain empty.
<asp:BoundField DataField="EmailAddress" HeaderText="Refer Patient"
SortExpression="EmailAddress"
DataFormatString="<a href=mailto:{0}>{0}<?subject=Email%20Subject&body=Email%20Body%20Text > </a>"
HtmlEncode="false"
HtmlEncodeFormatString="false" />
Any suggestions on where I am going wrong?

You can switch to TemplateField, then you have much more control over the generated HTML.
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
Email Me
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

You have invalid HTML, your HTML href attribute value is not wrapped in quotes, try this:
<asp:BoundField DataField="EmailAddress" HeaderText="Refer Patient"
SortExpression="EmailAddress"
DataFormatString='Email Me'
HtmlEncode="false"
HtmlEncodeFormatString="false" />

Related

How to encode html data in asp / vb.net boundcolumn datagrid?

I have some data in database which I am binding it to a bound column.
Data contains many html tags.
But I want to display it as TEXT only "NOT TO RENDER IT"
I am not sure because HTMLENCODE property doesn't work with boundcolumn.
Please help.
Also just to add I have multiple datagrids binding with bind() function and are using one event handler Itemdatabound.
<asp:boundcolumn datafield="content" readonly="True" headertext="Product ID ">
<headerstyle horizontalalign="Center" width="100px"></headerstyle>
<itemstyle horizontalalign="Left" width="100px"></itemstyle>
</asp:boundcolumn>
Prevent HTML encoding in auto-generated GridView columns
extract from possible solution from above link:
<asp:TemplateField HeaderText="myLink" SortExpression="myLink">
<ItemTemplate>
<asp:Literal ID="litHyperLink" runat="server" Text='<%# Bind("myLink", "{0}") %>' />
</ItemTemplate>
</asp:TemplateField>
Or bind your own columns, also shown in above link
Server.HtmlDecode()
This will allow you to print the tags without rendering them to html.
http://msdn.microsoft.com/en-us/library/hwzhtkke(v=vs.110).aspx

How to fix the width for each column in GridView?

How can I fix the width for each column in GridView. My GridView keeps extend along with data in the cell. I need it to skip to new line when it reach the right side of the cell. This is my code in .aspx file:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="Emp_ID" DataSourceID="LinqDataSource1"
AllowPaging="True" AllowSorting="True" Width="900px" HorizontalAlign="Center" >
<Columns>
<asp:BoundField DataField="Emp_ID" HeaderText="ID"
InsertVisible="False" ReadOnly="True" SortExpression="Emp_ID"/>
<asp:BoundField DataField="Emp_Username"
HeaderText="Username" SortExpression="Emp_Username" />
<asp:BoundField DataField="Emp_Password"
HeaderText="Password" SortExpression="Emp_Password" />
<asp:BoundField DataField="Emp_Name"
HeaderText="ชื่อพนักงาน" SortExpression="Emp_Name" />
<asp:BoundField DataField="Emp_Address"
HeaderText="ที่อยู่" SortExpression="Emp_Address" />
<asp:BoundField DataField="Emp_Tel"
HeaderText="เบอร์โทรศัพท์" SortExpression="Emp_Tel" />
<asp:TemplateField HeaderText="รูปพนักงาน" SortExpression="Emp_Picture">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Emp_Picture") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="Image2" runat="server" Height="70px"
ImageUrl='<%# Eval("Emp_Picture", "{0}") %>' Width="50px" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Status" HeaderText="สถานะ"
SortExpression="Status" />
<asp:HyperLinkField DataNavigateUrlFields="Emp_ID"
DataNavigateUrlFormatString="AdminUpdate.aspx?Emp_ID={0}" Text="Edit" />
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="ChkSelectAll" runat="server"
AutoPostBack="True" oncheckedchanged="ChkSelectAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chk" runat="server" AutoPostBack="True" oncheckedchanged="Chk_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here's my design view:
As you can see, the first 4 columns has no problem with that until column 5. It keeps extend cause all GridView extend out of the page
Set itemstyle width of every column.For example.
<asp:BoundField DataField="Emp_Address"
HeaderText="ที่อยู่" SortExpression="Emp_Address">
<ItemStyle Width="200px" HorizontalAlign="Left" />
</asp:BoundField>
Wrapping is done based on words so that any single word is not broken in two lines.
So won't work for you if your data has long string without space.
The problem is that you can't insert spaces on your own because that may change the meaning of data.
While showing in grid we show only that long string which can be accommodated in column and then add "..." (only if string is more than what is showing) and then add a tooltip to show the full string.
That way the grid formatting is not compromised and if user wants he can hover his mouse and see the whole string.
hope this helps Example
Try setting the property RowStyle-Wrap of the GridView to True.
You can use ItemStyle-Width to fix the column width ,but in case you enter characters which can not be enclosed in given width (As seen in your image) ,column will expand as per the inputs so you can use RowStyle-Wrap property of gridview
<asp:GridView ID="grdVwtrial" runat="server" RowStyle-Wrap="true">
RowStyle-Wrap==true should work I guess. For more clarifications refer this:
http://forums.asp.net/t/1263769.aspx

Hide cells in GridView based on another column

I have the following GridView:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="SysInvoiceID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="InvoiceID" HeaderText="SysInvoiceID" ReadOnly="True" SortExpression="SysInvoiceID" />
<asp:BoundField DataField="BillMonth" HeaderText="BillMonth" SortExpression="BillMonth" />
<asp:BoundField DataField="InvoiceDate" HeaderText="InvoiceDate" ReadOnly="True" SortExpression="InvoiceDate" />
<asp:BoundField DataField="InvoiceNumber" HeaderText="InvoiceNumber" SortExpression="InvoiceNumber" />
<asp:BoundField DataField="Net" HeaderText="Net" SortExpression="Net" />
<asp:BoundField DataField="VAT" HeaderText="VAT" SortExpression="VAT" />
<asp:BoundField DataField="Gross" HeaderText="Gross" SortExpression="Gross" />
<asp:ButtonField CommandName="ViewInvoice" HeaderText=" " ShowHeader="True" Text="View" />
</Columns>
</asp:GridView>
The very last column (ButtonField) is one I created myself just to include the text 'View' on each row, which when clicked, will bring up a PDF invoice.
I'm not sure if this is even possible, but I was wondering if it was possible to add some sort of validation for that column or something, so that if the 'InvoiceID' column is blank, the 'View' link on the corresponding row won't show up.
I felt close to doing this by going on split view in Visual Studio and then the 'Edit Columns' button on GridView tasks, but like I said I'm not sure if it's possible to do it this way and may have to resort to simply coding it.
Thanks for any help!
Use a <TemplateField> instead of a <ButtonField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" Text="View"
Visible='<%# Eval("IsEmpty(InvoiceID)") %>' CommandName="ViewInvoice" />
</ItemTemplate>
</asp:TemplateField>
And add a method to your page that is IsEmpty(string id) or whatever type your id is, and just check to see if it's empty first.
You can also add a CommandArgument attribute to the Button that will let you specify what the argument to it will be.
Use a placeholder...
<asp:Placeholder runat="server" ID="plView" Visible="<%# Convert.ToBoolean(InvoiceID == null) ? false : true %>">
<asp:ButtonField CommandName="ViewInvoice" HeaderText=" " ShowHeader="True" Text="View" />
</asp:Placeholder>

How to pass UserID or UserName into another page in asp.net membership feature using Query String?

I have used asp.net membership feature in my project. My code in 'manage-users.aspx' is;
<asp:GridView runat="server" ID="gridUserAccounts" SkinID="gridviewSkin" PageSize="5">
<Columns>
<asp:BoundField HeaderText="User Name" DataField="UserName" />
<asp:BoundField HeaderText="Email" SortExpression="Email" DataField="Email" />
<asp:BoundField HeaderText="Last Login Date" SortExpression="LastLoginDate" DataField="LastLoginDate" />
<asp:BoundField HeaderText="Last Activity Date" SortExpression="LastActivityDate" DataField="LastActivityDate" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" NavigateUrl='<%# "manage-user-detail.aspx?UserID=" %>' ID="linkNavigate" Text="View Detail" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
my code behind for this grid view is this;
if (!Page.IsPostBack)
{
gridUserAccounts.DataSource = Membership.GetAllUsers();
gridUserAccounts.DataBind();
}
Now, my question is "How do pass the selected userID into another page i-e 'manage-user-detail.aspx' page using querystring in this 'item template' (in NavigateUrl property).
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink runat="server" NavigateUrl='<%# "manage-user-detail.aspx?UserID=" %>' ID="linkNavigate" Text="View Detail" />
</ItemTemplate>
</asp:TemplateField>
And "How do i show the the user details (catch querystring first and then) and show result in fromview in 'manage-user-detail.aspx' page.
Any help will be apreciatable.
Try this:
NavigateUrl='<%# string.Format("manage-user-detail.aspx?UserID={0}",Eval("UserID")) %>'
You can alway access the username this way:
HttpContext.Current.User.Identity.Name
UPDATE
If you want the data for a specific user you will need to retrieve the MembershipUser instance by username:
var userName = "someUserName";
var membershipUser = System.Web.Security.Membership.GetUser(userName);
Here are the available infos on the MembershipUser class:
http://msdn.microsoft.com/en-us/library/system.web.security.membershipuser.aspx

Problems with grid view in ASP.NET

I am displaying a table with user email ID and name in a GRID view in a ASP.NET web Page.
I want a send mail button or link next to each row. SO that when I click the send mail button the useremail in that row will be copied and the page will be redirected to send mail page. How to do it?
BTW i am using MYSQL
You can use a HyperLink field:
<asp:HyperLinkField DataTextField="email" HeaderText="Mail To:" DataNavigateUrlFields="email" Target="_blank" DataNavigateUrlFormatString="SendMail.aspx?email={0}" SortExpression="email" />
hope Thisa helps
Probably it would be like this
<asp:GridView runat="Server" id="GrdVw_Email">
<asp:BoundField DataField="Email" HeaderText="Email"/>
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:BoundField DataField="Email" DataFormatString="email.aspx?id={0}" DataText="SendEmail"/>
</asp:GridView>
i just put the code from my mind, but you should get the idea

Categories

Resources