I have a gridview in which I want to load a users details. In this gridview I want to make the users phone number a hyperlink. This is so they can click on the link and it automatically rings the number using the phone software stored on the their pc. This works fine if you use the below syntax in html:
07123456789
My issue is that I want to do this in a gridview which populattes the phone number. The html has to have the 'tel:' bit in front of it first. I have tried everything please help! I want essentially above but to render in gridview with the loaded HomeNo where the phone number should be...HElp!
Gridview:
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ds">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:HyperLinkField DataTextField="HomeNo" HeaderText="HomeNo" NavigateUrl="tel:" />
</Columns>
</asp:GridView>
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ds">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("HomeNo", "tel:{0}") %>'
Text='<%# Eval("NomeNo") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
you would need to do this inside of an also if you have data it's reading from you need to do some code inside of the DataBound Event of the DataGrid
for example I have names and email addresses as a link in my current datagrid here is how I do it
<asp:TemplateColumn HeaderText="Scheduler" HeaderStyle-Font-Bold="true" HeaderStyle-Width="145">
<ItemTemplate>
<a href='<%#Eval("Email_Address") %>' ><%# Eval("Scheduler") %></a>
</ItemTemplate>
<HeaderStyle Font-Bold="True" />
</asp:TemplateColumn>
protected void dgShippers_DataBinding(object sender, EventArgs e)
{
foreach (DataRow r in dtShippers.Rows)
{
if (!System.Uri.IsWellFormedUriString(r.ItemArray[3].ToString(), UriKind.Absolute))
{
var tempHref = "<a href=mailto:" + r.ItemArray[4].ToString() + " />" + r.ItemArray[3].ToString()+ "</a>";
r.Table.Rows[0]["Scheduler"] = tempHref;
}
}
}
Related
I have added a buttonfield named "accept" in the gridview..I want to update the column 'status' of bitfield to '1' of that specific row when admin clicks on accept.. Im working on c#
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" runat="server" Width="1000px"
AllowPaging="True" PageSize="8"
CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr" DataSourceID="SqlDataSource1" AllowSorting="True">
<Columns>
<asp:ButtonField Text="Accept" CommandName="Update" runat="server"/>
<asp:BoundField DataField="fname" HeaderText="fname" SortExpression="fname" />
<asp:BoundField DataField="emailid" HeaderText="emailid" SortExpression="emailid" />
<asp:BoundField DataField="contact" HeaderText="contact" SortExpression="contact" />
<asp:BoundField DataField="type" HeaderText="type" SortExpression="type" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbrubyConnectionString3 %>" SelectCommand="SELECT seller.fname, seller.emailid, seller.contact,seller.type, login.username, login.password FROM seller INNER JOIN login ON seller.sid=login.lid where login.status= ORDER BY login.createdate ">
Add an event handler for GridView1_RowCommand, looking for the command "Update", and grab the DataItem so you know which item to update, then update it in the database, and then rebind your gridview.
You could also make an ajax call to update the value, which would be faster (less data to transmit and receive), and wouldn't require a full page refresh, but that is more work to set up.
Add an identifier (CommandArgument) to your command by changing:
<asp:ButtonField Text="Accept" CommandName="Update" runat="server"/>
to:
<asp:ButtonField Text="Accept" CommandName="Update" runat="server"
CommandArgument="<%# Eval("emailid") %>"/>
Add event handler by changing:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" runat="server"
Width="1000px" AllowPaging="True" PageSize="8" CssClass="Grid"
AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"
DataSourceID="SqlDataSource1" AllowSorting="True">
to:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" runat="server"
Width="1000px" AllowPaging="True" PageSize="8" CssClass="Grid"
AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"
DataSourceID="SqlDataSource1" AllowSorting="True"
OnRowCommand="GridView1_OnRowCommand">
Then write your update in the backend by adding:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch(e.CommandName)
{
case "Accept":
var email = e.CommandArgument.ToString();
Accept(email); // write this function
break;
}
}
I have a problem in gridview, as per requirement i have set No of Records per page = 4 in gridview. I have to select Checkbox against every complaint but problem is then when i got to next pge in gridview and e.g fro 1 to 2 then when i come back to page 1 then it doesn't show TICK in check boxes . It doesn't remember my selection when i browse to and back to page.
<asp:GridView ID="GridViewSmsComplaints" AllowPaging="True" PageSize="4" runat="server" AutoGenerateColumns="False" CssClass="mGrid" BorderColor="#333333" Width="550px" OnPageIndexChanging="GridViewSmsComplaints_PageIndexChanging" >
<Columns>
<asp:BoundField HeaderText="ID" DataField="ID" />
<asp:BoundField HeaderText="Recieving Date" DataField="RecievingDate" />
<%--<asp:BoundField HeaderText="ToMobileNo" DataField="ToMobileNo" /> --%>
<asp:BoundField HeaderText="FromMobileNo" DataField="FromMobileNo" />
<asp:BoundField HeaderText="Message" DataField="Message" >
<ItemStyle Wrap="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="IsComplaint">
<ItemTemplate>
<asp:CheckBox ID="ckboxIsComplaint" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsComplaint").ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
please check the above link.here your problem was clearly explained here.i think so it may be helpfull
As per comments...
If you do not update the underlying database by processing the OnCheckChanged event of the check box, then it will simply be reading the same data all the time.
From How to add event for Checkbox click in Asp.net Gridview Column, I have extracted the required information and tried to modify to fit your initial question.
<asp:TemplateField HeaderText="IsComplaint">
<ItemTemplate>
<asp:CheckBox ID="ckboxIsComplaint" runat="server" Checked='<%# Convert.ToBoolean(Eval("IsComplaint").ToString()) %>' OnCheckedChanged="chk_CheckedChanged" AutoPostBack="true/>
</ItemTemplate>
</asp:TemplateField>
add checkbox change event in aspx.cs page
protected void chk_CheckedChanged(object sender, EventArgs e)
{
GridViewRow row = ((GridViewRow)((CheckBox)sender).NamingContainer);
<your data source>.Rows[row.DataItemIndex]["B"] = ((CheckBox)GridViewSmsComplaints.Rows[row.RowIndex].FindControl("ckboxIsComplaint")).Checked;
}
I'm displaying a Gridview which shows a list of questions with a checkbox for pass or fail. What I would like to do is when they tick the checkbox for a fail a textbox appears in the next column to give the reason why. The code for my Gridview is as follows
<asp:GridView ID="QuestionsGrid" runat="server" AutoGenerateColumns="False"
BorderStyle="None" class="gridView"
GridLines="None" ShowFooter="True" TotalRows="0"
Width="950px" CellPadding="5" CssClass="gridView"
EmptyDataText="No rows found."
style="margin-left: auto; margin-right: auto;"
OnRowDataBound="QuestionsGrid_RowDataBound" IgnoreFlagIdpsc=""
OnRowEditing="QuestionsGrid_RowEditing" onRowCommand="QuestionsGrid_RowCommand" >
<Columns>
<asp:BoundField ItemStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" Width="200px"></ItemStyle>
</asp:BoundField>
<asp:BoundField ItemStyle-HorizontalAlign="Left" >
<ItemStyle HorizontalAlign="Left" Width="500px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Passed" >
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked="true" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Value" >
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="100px" Font-Size="10pt"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I have tried setting an event onCheckChanged with my CheckBox which doesn't work. I would like to do this without using editable buttons for my GridView.
The next code should work:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
var checkbox = sender as CheckBox;
//version 1: show the text box on click
checkbox.Parent.FindControl("TextBox1").Visible = true;
//version 1: show the text box based on checkbox state
checkbox.Parent.FindControl("TextBox1").Visible = checkbox.Checked;
}
Don't forget to add the handler (and the autopostback) from aspx markup with
<asp:TemplateField HeaderText="Passed">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked="true" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
I have entered a value in the textbox, however when I clicked the button to get the value at server side, it still retrieved the old value.
Here is my code:
aspx:
<asp:GridView ID="gvTicketSkus" runat="server" AutoGenerateColumns="false"
CssClass="innergv" HeaderStyle-CssClass="innergvHeader" GridLines="Horizontal"
Width="570px">
<Columns>
<asp:BoundField HeaderText="Sku" DataField="TicketItemCode" />
<asp:BoundField HeaderText="TICKET TYPE" DataField="TicketItemCodeDescription" />
<asp:BoundField HeaderText="Tickets#" DataField="NumberOfWristbandsPerTicket" Visible="false" />
<asp:BoundField HeaderText="PRICE" DataField="Price" DataFormatString="{0:c}" />
<asp:TemplateField HeaderText="QUANTITY">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" TextMode="SingleLine" MaxLength="4" Width="80px" CssClass="quantity" Text="0"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
C#:
foreach (GridViewRow gvr in gvTicketSkus.Rows)
{
sku = gvr.Cells[0].Text;
quantity = Convert.ToInt32(((TextBox)gvr.FindControl("txtQuantity")).Text);
if (quantity > 0)
{
pendingOrder.Add(sku, quantity);
}
}
As you see when I get the value of txtQuantity, it gave me the old value, instead of the one I type in.
I guess there is some issue in postback.
You can try using
Request.Form[((TextBox)gvr.FindControl("txtQuantity")).ClientID];
To get exactly what was posted to the server.
You may need to work on the syntax. I can't test it right now.
Merged with GridView sorting works once only.
Please help me, I set Allowsorting="true" but sorting is not working in my GridView. I want automatic sorting i.e. sorting without handling its event.
Here is code of aspx page:
<asp:GridView ID="gdvSignatureLines" runat="server" CssClass="Grid1" AutoGenerateColumns="False"
SkinID="PagedGridView" AllowPaging="True" AllowSorting="True" DataKeyNames="Id"
onrowcommand="gdvSignatureLines_RowCommand"
onrowdeleting="gdvSignatureLines_RowDeleting"
onrowediting="gdvSignatureLines_RowEditing">
<PagerStyle CssClass="gridPager" HorizontalAlign="Right" />
<Columns>
<ucc:commandfieldcontrol headertext="Actions" showdeletebutton="true" buttontype="Image"
deleteimageurl="~/App_Themes/Default/images/delete.png" showeditbutton="true"
editimageurl="~/App_Themes/Default/images/edit.png" deleteconfirmationtext="Are you sure you want to delete?">
<ItemStyle HorizontalAlign="Center" Width="60px" />
</ucc:commandfieldcontrol>
<asp:BoundField DataField="SortOrder" HeaderText="Line" SortExpression="SortOrder" />
<asp:TemplateField HeaderText="Type">
<ItemTemplate>
<asp:Label ID="lblglTypeId" runat="server" Text='<%# Eval("GeneralLookup.LookupItem") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Label">
<ItemTemplate>
<asp:Label ID="lblglLabelId" runat="server" Text='<%# Eval("GeneralLookup1.LookupItem") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Caption" HeaderText="Caption" SortExpression="Caption" />
</Columns>
<EmptyDataTemplate>
<div class="divEmptyListingGrid">
--- No Signature Line Exists ---
</div>
</EmptyDataTemplate>
</asp:GridView>
Here is the code of CS file:
protected void LoadSignatureList(int reportId, string reportName)
{
lblHeading.Text = "Signature Line for " + reportName;
ReportOptionsBO reportOptionsBO = new ReportOptionsBO();
this.gdvSignatureLines.DataSource = reportOptionsBO.GetReportSignatureLineByReportId(reportId);
this.gdvSignatureLines.DataBind();
}
When I click on the Header of column "Line" or "Caption", nothing happens.
I have one more grid that is working fine. The difference between both is, data is bound to this grid on runtime. But the other grid's datasource is preset.
My current grid has not these options of Enable Paging and Enable Sorting.
Please help as soon as possible.