Populate values in pop up from the grid in asp.net - c#

<asp:GridView ID="UserTable" runat="server" AllowPaging="False" SelectedIndex="0" DataKeyNames="UserID" ShowHeaderWhenEmpty="True"
OnRowDeleting="UserTable_RowDeleting" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Edit Controls" ItemStyle-Width="15%">
<ItemTemplate>
<%-- <asp:LinkButton ID="lnk_Edit" ToolTip="Edit User" CommandArgument='<%# Eval("UserID") %>' CommandName="Edit1" runat="server">--%>
<asp:ImageButton ID="img_Edit" src="Styles/Images/Edit.jpg" runat="server" style="border-style: none" CommandArgument='<%# Eval("UserID") %>'
CommandName="Edit1" />
<%--</asp:LinkButton>--%>
<asp:PopupControlExtender ID="PopUCtrlExt_Edit" runat="server" DynamicServicePath=""
Enabled="True" ExtenderControlID="" TargetControlID="img_Edit" PopupControlID="pnl_updateUser">
</asp:PopupControlExtender>
I wanted to get a pop up when I click the edit image inside my grid view. When I tried with a edit image inside a link the pop up was doing post back so I had to remove the link. Now How can i get the values of the selected row and use that value in the pop up panel which has
<asp:ListBox ID="listboxE_RoleName" runat="server" DataSourceID="SurelyKnown" DataTextField="RoleName" DataValueField="RoleName"></asp:ListBox>
<asp:TextBox ID="txtE_Email" runat="server" CssClass="style23"></asp:TextBox>
I want to edit the selected value. How to populate the values of selected row in the pop up panel in client side. If possible also a fix for the pop up postback when I use the image button inside the link. Thanks

Check these links
http://mattberseth.com/blog/2007/07/modalpopupextender_example_for.html
http://mattberseth.com/blog/2008/06/masterdetail_with_the_gridview_1.html
http://mattberseth.com/blog/2008/04/masterdetail_with_the_gridview.html
http://www.aspdotnet-suresh.com/2011/03/how-to-show-modalpopup-to-edit-gridview.html

Related

I have to click the update button twice and the first time all values in the cells of the Gridview disappear

I have a Gridview set up and populated by binding my data. I have created a column that holds an "Edit" button. Clicking that button changes all of my fields to a text box populated with the data that is pulled from the database and replaces the "Edit" button with an "Update" and "Cancel" button. Up to this point all is working as intended. I change the value in the textboxes that I want to update and click the "Update" button. At this point everything is cleared out of all of the text boxes in each cell. I can enter the data again at this point and click the "Update" button a second time and any values that I have entered (the second time) will be passed back to my updating event procedure, but that is not quite the functionality I'm looking for.
I have run across a couple reports of the "Edit" button requiring 2 clicks to function, but the fixes didn't really apply to my situation.
This is my page_load
{
if (!this.IsPostBack)
{
Build_DDL();
Build_Turn_Checkbox_List();
Show_Data();
}
CheckBox_Selected_Values();
}
This is my gridview declaration:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" HeaderStyle-CssClass="headerClass" HeaderStyle-VerticalAlign="Bottom"
RowStyle-Wrap="true" HeaderStyle-Wrap="true" OnDataBound ="OnDataBound" AllowSorting="True" HeaderStyle-Height="50px"
OnSorting="GridView1_SelectedIndexChanged" CssClass="reportData" OnRowDataBound="GridView_OnRowDataBound"
OnRowCancelingEdit="GridView1_RowCancelEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<HeaderStyle VerticalAlign="Bottom" Wrap="True" Height="50px" />
<RowStyle Wrap="True" CssClass="oddRow" />
<AlternatingRowStyle CssClass="evenRow" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID ="btn_Edit" runat="server" Text="Edit" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btn_Update" runat="server" Text="Update" CommandName="Update"/>
<asp:Button ID="btn_Cancel" runat="server" Text="Cancel" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="State" Visible="false">
<ItemTemplate>
<asp:Label ID="lbl_state" runat="server" Text='<%#Eval("STATE") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_state" runat="server" Text='<%#Eval("STATE") %>'></asp:TextBox>
</EditItemTemplate>
There are more fields, but they are all built exactly the same.
Here is my update code:
{
//declare variables
string stateVal;
//set up textboxes
GridViewRow row = GridView1.Rows[e.RowIndex];
TextBox txt_State = (TextBox)row.FindControl("txt_state");
stateVal = txt_State.Text;
}
I didn't notice that when I clicked the "Edit" button on row 2, it was row 5 that was transitioning into text boxes. This was because I have the following code creating groupings in the gridview and each group creates a new row that is not accounted for in the row index scheme:
helper.RegisterGroup("State", true, true);
helper.RegisterGroup("Project Type", true, true);
helper.GroupHeader += new GroupEvent(Helper_GroupHeader);
helper.ApplyGroupSort();
GridView1.DataBind();
I will have to somehow account for the group headers and adjust the neweditindex accordingly.

C# Edit Command Name in Gridview

In my gridView I've inserted the edit command name for every single row.
Now I need when the database value of myDate is not null stopping the edit in this row.
I tried this solution, but in GV see the icon stop.gif when the database value of myDate is not null, but if click in stop.gif the edit row is open, why?
Can you help me?
Thanks in advance.
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<center>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server"
ImageUrl='<%#(String.IsNullOrEmpty(Eval("myDate").ToString()) ? "/Images/edit.gif" : "/Images/stop.gif")%>'
ToolTip="Edit" /></center>
</ItemTemplate>
<EditItemTemplate>
<center>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="/Images/update.gif"
ToolTip="Update" />
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="/Images/cancel.gif"
ToolTip="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
If you just make the image url blank, it does not mean that you are not rendering the control. The button will still render. What you could do instead is like below
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server"
ImageUrl='/Images/stop.gif'
Visbile = '<%#Eval("myDate").HasValue %>'
ToolTip="Edit" />

how to change text of label in datalist at page load

<asp:datalist ID="Datalist1" runat="server"
Width="500px" >
<ItemTemplate>
<asp:Button ID="btnviewfullprofile" runat="server" Text="View Full Profile" ToolTip="Click for Full Profile of User" CommandArgument='<%#Eval("Uid")%>' CommandName="fullprofile" />
<asp:Button ID="sendinterest" runat="server" Text="Send Interest" CommandArgument='<%#Eval("Uid")%>' CommandName="sendinterest" />
<asp:Label ID="lblstatus" runat="server" Visible="False" ></asp:Label>
</ItemTemplate>
</asp:datalist>
text of label will change according to the value of status stored in database.
code for button
if (e.CommandName == "fullprofile")
{
int Id = int.Parse(e.CommandArgument.ToString());
Response.Redirect("~/FullProfile.aspx?Id=" + Id);
`enter code here` }
but what should i write for label so that text of label should change itself based on value of status stored in database
If I understand you correctly, you need to change the HTML to something like:
<asp:Label ID="lblstatus" runat="server" Visible="False"
Text='<%# Eval("DatabaseField") %>' />
You are already using this for the CommandArgument of the button. Obviously you need to replace 'DatabaseField' with the name of the field that you want to show as text. ASP.net will fill the Text attribute with the correct value from your datasource.
as you are binding commandargument of the button from database, same way you can bind the text property of the label
<asp:Label ID="lblstatus" runat="server" Visible="False" Text= '<%#Eval("textfield")%>' ></asp:Label>
If you need more advance control then you need to set them when items are getting bound see here fore details http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.itemdatabound.aspx

Delete and Edit button on new line in a single column

I am trying to add edit, delete button on my gridview using,
<asp:CommandField HeaderText="Edit/Delete" ShowEditButton="true" ShowDeleteButton="True" />
however it looks like this now,
I want Delete button on a new row, what can I do ?
like this
Edit
Delete
Try
first convert commandbuttons to template then
adding <br /> between edit button and delete button
UPDATE In Gridview Task then Select the commands that you want to convert to TemplateField in "Selected Fields:" then check your source code. You will see in the ItemTemplate
<asp:ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>

Visibility of an ASP.Net button which depends if a file exists in database

I have a gridview which has a few rows (each with a unique rowId), and each line has a FileUpload control, now everything works okay with FileUpload.
(my uploaded file database image can be seen below)
I have the download button, which also works okay, however I want to make this button invisible if no file exists for the corresponding row.
Nothing proper comes to my mind.
My button and FileUpload control:
<asp:TemplateField HeaderText="BatchList">
<EditItemTemplate>
<asp:ImageButton ID="ibt_Download" runat="server" src="Images/Download.png" CommandName="Download" CommandArgument='<%# Container.DataItemIndex %>' ></asp:ImageButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UploadBatchList">
<HeaderTemplate>
<asp:Label ID="lbl_Header" ToolTip="Upload Batch List" runat="server" Text="UBL"></asp:Label>
</HeaderTemplate>
<EditItemTemplate>
<asp:FileUpload ID="fu_UploadBatchList" runat="server" />
<asp:Button ID="btn_Upload" runat="server" Text="Upload" OnClick="btn_Upload_Click" />
</EditItemTemplate>
</asp:TemplateField>
This is how it looks on my gridView
When gridview is first created the green dots must not be visible if a file has been uploaded before.
My file database:
You can check some property of the data item (DocName in your case) if it contains a value (it might not work when copy-pasted, I'm a little bit improvising):
<asp:Button ID="btn_Upload" runat="server"
Text="Upload"
Visible='<% DataBinder.Eval(Container.DataItem, "DocName") == null %>
OnClick="btn_Upload_Click" />
Or you can create a function that will evaluate the visibility. See Mastering ASP.NET DataBinding for more.

Categories