Creating a popup from inside the Item Command event - c#

is there a way I can create a popup or dialog window from inside a gridview's ItemCommand event?
What I am trying to do is if the transaction failed, I want to show the error message in a popup when they click the image button.
This is as far as I have gotten. Also how can I put the error message into the dialog? Should I save the message to the grid view in a hidden column? I'm not sure how to pass that value into the dialog box.
the ascx
<telerik:RadGrid ID="TransactionListGrid" CssClass="DataGrid" AutoGenerateColumns="False" runat="server" AllowSorting="True"
AllowPaging="True" GridLines="None" EnableEmbeddedSkins="false" Skin="Growll" Width="700px" OnNeedDataSource="TransactionListGrid_NeedDataSource"
ShowHeadersWhenNoRecords="true" CellSpacing="0" OnItemDatabound="TransactionListGrid_ItemDataBound" OnItemCommand="TransactionListGrid_ItemCommand">
<ClientSettings EnableRowHoverStyle="true">
<Selecting AllowRowSelect="True"></Selecting>
</ClientSettings>
<PagerStyle Position="Top" />
<MasterTableView DataKeyNames="Id,Amount,IsCredit,IsCancelled" CommandItemDisplay="Top">
<NoRecordsTemplate>
<div>
No transactions found.</div>
</NoRecordsTemplate>
<CommandItemSettings ShowAddNewRecordButton="false" />
<Columns>
<telerik:GridDateTimeColumn HeaderText="Date" DataField="Date" />
<telerik:GridBoundColumn HeaderText="Order ID" DataField="Order_Id" />
<telerik:GridCheckBoxColumn HeaderText="Credit" DataField="IsCredit" />
<telerik:GridCheckBoxColumn HeaderText="Cancelled" DataField="IsCancelled" />
<telerik:GridCheckBoxColumn HeaderText="Failed" DataField="IsFailed" UniqueName="FailedCheckBox"/>
<telerik:GridButtonColumn HeaderText="Error" UniqueName="ErrorMessageButton" ButtonType="ImageButton"/>
<telerik:GridNumericColumn HeaderText="Amount" DataField="Amount" DecimalDigits="2" DataFormatString="{0:$######0.00}" />
<telerik:GridBoundColumn HeaderText="Last Four" DataField="CardLastFour" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
c#
protected void TransactionListGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == "ErrorMessage")
{
}
}

There are a few ways to do this, but the easiest way is probably using AJAX. Put a RadToolTip on your page and ajaxify the tooltip and grid using the RadAjaxManager (or RadAjaxPanel). With the tooltip and grid ajaxified, you can just call the RadToolTip.Show() method in the ItemCommand event of the grid.

Related

Why my asp.net MODAL doesn't display data?

I am trying to display a gridview inside ajax MODAL but it doesn't show the gridview. It shows every other element that I put INSIDE it but not a gridivew.
I tried to display gridview outside the modal and it works but not inside modal.
Why ?
Code:
<asp:Panel ID="pnlLastHearingDates" CssClass="modalPopup" runat="server" HorizontalAlign="Center" Visible="true">
<asp:GridView runat="server" ID="grdViewLastHearingDates" AllowPaging="true" PageSize="5" OnPageIndexChanging="grdViewLastHearingDates_PageIndexChanging"
OnRowCommand="grdViewLastHearingDates_RowCommand" PagerStyle-BackColor="#99CC99" HeaderStyle-BackColor="#99CC99" DataKeyNames="pk_Cases_CaseID" PagerStyle-Font-Size="12.5px" PagerStyle-ForeColor="Black" PagerStyle-HorizontalAlign="Center" AutoGenerateColumns="false" OnRowEditing="grdViewLastHearingDates_RowEditing"
CssClass="table table-condensed table-bordered table-striped table-responsive">
<Columns>
<asp:BoundField DataField="pk_Cases_CaseID" HeaderText="Case ID" />
<asp:BoundField DataField="CaseNo" HeaderText="Case No" />
<asp:BoundField DataField="NextHearingDate" HeaderText="Next Hearing Date" />
<asp:BoundField DataField="DaysRemaining" HeaderText="Days Remaining" />
</Columns>
</asp:GridView>
</asp:Panel>
<asp:Button ID="btnShowLasthearingDates" runat="server" OnClick="btnShowLasthearingDates_Click" CssClass="btn btn-primary" />
<asp:ModalPopupExtender ID="mdlLastHearingDates" runat="server" TargetControlID="btnShowLasthearingDates" PopupControlID="pnlLastHearingDates">
.cs code:
protected void btnShowLasthearingDates_Click(object sender, EventArgs e)
{
ShowLastHearingDates();
pnlLastHearingDates.Visible = true;
}
The issue here is probably with the TargetControlId attribute of the ModalPopupExtender.
Try removing the Button ID from there and instead take a Hidden Field control in your aspx page and give it an ID. Now put that ID into the TargetControlId attribute and try clicking your button.
Your code would look like this :
<asp:HiddenField ID="HdnFld1" runat="server" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="MPE" runat="server"
CancelControlID="btnCancel"
TargetControlID="HdnFld1" PopupControlID="Panel1"
PopupDragHandleControlID="PopupHeader" Drag="true"
BackgroundCssClass="ModalPopupBG">
</asp:ModalPopupExtender>
Also, you can keep CausesValidation="false" for your button just in case it stops postback due to validation, but again, you might handle it since that would postback without any kind of data checks on the client side.
Hope this helps.

Copy gridview cell value to the clipboard

I have a gridview with some values. If the user clicks on a link or button (here I took a Buttonfield with the text 'Copy') on one of the rows, it should copy a cell value of that row to the clipboard.
Is something like this possible in asp.net c# ?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource1" Visible="False" OnRowDataBound="GridView1_RowDataBound"
onselectedindexchanged="GridView1_SelectedIndexChanged1">
<Columns>
<asp:BoundField DataField="Username" HeaderText="Username"
SortExpression="Username" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
<asp:CommandField ButtonType="Image" EditImageUrl="/images/edit.png" CancelImageUrl="/images/undo.png" UpdateImageUrl="/images/save.png" ShowEditButton="True" />
<asp:CommandField ButtonType="Image" ShowDeleteButton="True" DeleteImageUrl="/images/deletered.png" />
<asp:ButtonField Text="Copy" />
</Columns>
<EmptyDataTemplate>
No data available
</EmptyDataTemplate>
</asp:GridView>
There is no Onclick event available for a ButtonField. Otherwise I would think of using some javascript (I have seen that in other solutions)
Thanks for any input.
You can do that with windows form only, but since you are working on Web application you should write client side code which is javascript to copy data on client side not server side. checkout this link

Selection of checkboxes lost during pagination of gridview

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;
}

asp.net c# gridview buttons

I'm having trouble getting a gridview's button column to do anything. I'm using a DirectoryInfo object to get the details of a file. I put the filename and the date created into the gridview columns. The third column is a button column. I have set the datakeys(Name, CreationTime), named the button column's commandName to "sendcommand". I want to send the filename to another page. I have this code for the RowCommand event:
protected void gvFiles_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
if (e.CommandName == "sendcommand")
{
int index = Convert.ToInt32(e.CommandArgument);
string fileID = ((GridView)sender).DataKeys[index]["Name"].ToString();
Response.Redirect("irMain.aspx?#filename=" + fileID);
}
}
Nothing happens, except for a postback I think. How do I do this?
<asp:GridView ID="gvFiles" runat="server" Font-Name="Verdana" Font-Names="Verdana"
Width="401px" AutoGenerateColumns="False" BackColor="White"
BorderColor="Black" BorderStyle="Ridge" BorderWidth="2px"
DataKeyNames="Name,CreationTime"
>
<Columns>
<asp:HyperLinkField AccessibleHeaderText="File Name"
DataNavigateUrlFields="Name" DataNavigateUrlFormatString="~\Assets\reports\{0}"
DataTextField="Name" HeaderText="File Name" >
<HeaderStyle BackColor="#0033CC" ForeColor="White" />
</asp:HyperLinkField>
<asp:BoundField AccessibleHeaderText="Date" DataField="CreationTime"
DataFormatString="{0:d}" HeaderText="Date">
<HeaderStyle BackColor="Blue" ForeColor="White" />
</asp:BoundField>
<asp:ButtonField ButtonType="Button" Text="DO Stuff" CommandName="sendcommand"
HeaderText="WHAT?!" />
</Columns>
<AlternatingRowStyle BackColor="#6699FF" />
</asp:GridView>
You have to add the OnRowCommand attribute to your GridView in the ASPX, otherwise the GridView doesn't know what method to call when you execute a command on it.
AFAIK this is an entirely optional attribute and isn't generated via the designer so you have to add it manually when you want to use it.

User Control Properties?

Can I build a control that basically acts "like a MasterPage"?
What I mean to do is, say I have a grid like this in a number of pages:
<asp:UpdatePanel ID="AnnouncementsPanel" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="AnnoucementsGrid" runat="server" AutoGenerateColumns="false" DataKeyNames="Id" >
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Created" HeaderText="Date" />
<asp:BoundField DataField="Modified" HeaderText="Last Modified" />
<asp:ButtonField ButtonType="Button" Text="Process" CommandName="Process" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
I'd like to build a control that handles most of the codebehind, but I need to declare the columns for the grid declaratively in each case.
Is there a way to create a control like this?
<uc:CrudGrid ID="AnnouncementsCrud" runat="server">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Created" HeaderText="Date" />
<asp:BoundField DataField="Modified" HeaderText="Last Modified" />
<asp:ButtonField ButtonType="Button" Text="Process" CommandName="Process" />
</Columns>
</uc:CrudGrid>
or event better:
<uc:CrudGrid ID="AnnouncementsCrud" runat="server">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Created" HeaderText="Date" />
<asp:BoundField DataField="Modified" HeaderText="Last Modified" />
</Columns>
</uc:CrudGrid>
Maybe having to name the tag "Fields", but being able to drop the button, so it can be used in the UC's code-behind?
A lot of love to whoever has a positive answer on this <3
Found the exact solution I was looking for:
[DefaultValue((string)null)]
[Editor(typeof(System.Web.UI.Design.WebControls.DataControlFieldTypeEditor), typeof(UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public DataControlFieldCollection Columns
{
get { return Grid.Columns; }
}
this way I can expose the Columns from the grid in my own user control and edit the fields from the markup, keeping general functionalities within my UC
Depends on how positive you want it to be :-) You can always build your own control to do this. That is one option.
Another option is to create a helper object that attaches to the grid, and keep each grid separate.
Third option is to create a user control with the common code, and programmably add columns to the grid through the user control.
HTH.

Categories

Resources