I need to display a modal popup when gridview row is clicked(without any buttons), i managed to display popup by clicking the gridview row but dont know to bind values to textbox displayed in modal popup..
So i need help to
Bind gridview row(when clicked) values to modal popup textboxes
Modal popup textboxes should only be editable when a edit button(placed at bottom of modal popup) is clicked
After editing work is done, it should save the edited data when clicked save button(placed at bottom next to edit button)
As am new to asp.net please try to help me with your suggestions for my requirements.
Because of below code am able to show popup wen clicked gridview row but suggest me how to bind values to textbox:
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (row.DataItem == null)
{
return;
}
try
{
switch (e.Row.RowType)
{
case DataControlRowType.Header:
break;
case DataControlRowType.DataRow:
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand'");
e.Row.Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(grid, "Select$" + e.Row.RowIndex.ToString()));
e.Row.Attributes.Add("onclick", String.Format("javascript:$find('{0}').show();", ModalPopupExtender2.ClientID));
TextBox1.Text = grid.SelectedRow.Cells[0].Text;
TextBox2.Text = grid.SelectedRow.Cells[1].Text;
TextBox3.Text = grid.SelectedRow.Cells[2].Text;
TextBox4.Text = grid.SelectedRow.Cells[3].Text;
TextBox5.Text = grid.SelectedRow.Cells[4].Text;
ModalPopupExtender2.Show();
break;
}
}
catch
{
return;
}
}
HTML CODE:
<asp:Panel ID="editpanel" runat="server">
<table width="850px" border="1" class="color">
<tr>
<td align="center">
<asp:Label ID="Label1" runat="server" Text="Firstname" Width="150px"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Surname" Width="150px"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="Visits" Width="150px"></asp:Label>
<asp:Label ID="Label4" runat="server" Text="$ Speed" Width="150px"></asp:Label>
<asp:Label ID="Label5" runat="server" Text="Points" Width="150px"></asp:Label>
<asp:ImageButton id="ImageButton1" runat="server" src="close.png" onclick="close_Click" style="float:right; height: 16px;" ToolTip="To close window"/>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="cancell" runat="server" onclick="cancell_Click"
src="cancel.jpg" style="float:right; width: 16px;"
ToolTip="To cancel member" />
<asp:ImageButton ID="tickk" runat="server" onclick="tickk_Click" src="tick.jpg"
style="float:right; height: 16px;" ToolTip="To save member" />
<asp:ImageButton ID="Edit" runat="server" onclick="edit_Click"
src="edit.jpg" style="float:right; height: 16px; width: 16px;"
ToolTip="To edit member" />
</td>
</tr>
</table>
</asp:Panel>
<asp:ModalPopupExtender ID="ModalPopupExtender2" runat="server" TargetControlID="modal2" PopupControlID="editpanel" BackgroundCssClass="modalBackground"></asp:ModalPopupExtender>
<asp:ImageButton ID="modal2" runat="server" src="addmember.jpg" OnClick="modal2_click" Text="modal2" style="display:none;"/> // have created a dummy image button
Since am new to asp.net please try to help me with your suggestions.
Use this to bind your data with text box by using BindingSource (Just an example):
textBoxid.DataBindings.Add(new Binding("Text", customersBindingSource, "ID"));
textBoxname.DataBindings.Add(new Binding("Text", customersBindingSource, "NAME"));
textBoxcity.DataBindings.Add(new Binding("Text", customersBindingSource, "City"));
To make uneditable your text boxes, use this:
private void EditButton_Click(object sender, EventArgs e)
{
if (textBoxid.ReadOnly == true)
{
textBoxid.ReadOnly = false;
//how many text boxes you have, do the same here
}
else
{
textBoxid.ReadOnly = true;
//how many text boxes you have, do the same here
}
}
To save your edits, just run an UPDATE query with all your new data.
Related
I have a method that generates accordionpanes and panels and inside each accordionpane I create a button. This methode I use it in the listviewselectedindexchanged method to create the order object and fillup the body panel
protected void PanelCreator(Order order, List<Panel> pnllist)
{
Panel panelHead = new Panel();
panelHead.ID = "pH" + order.product;
panelHead.CssClass = "cpHeader";
//Add Label inside header panel to display text
Label lblHead = new Label();
lblHead.ID = order.product;
lblHead.Text = order.productName + " €" + order.priceValue;
panelHead.Controls.Add(lblHead);
//Create Body Panel
Panel panelBody = new Panel();
panelBody.ID = "pB" + order.product;
panelBody.CssClass = "cpBody";
AccordionPane ap = new AccordionPane();
foreach (Panel p in pnllist)
{
panelBody.Controls.Add(p);
}
Button btn = new Button();
btn.ID = "btn" + order.product;
btn.Text = "Toevoegen";
btn.Click += new EventHandler(btn_Click);
panelHead.Controls.Add(btn);
ap.ID = "ap" + order.product;
ap.HeaderContainer.Controls.Add(panelHead);
ap.ContentContainer.Controls.Add(panelBody);
accMenu.Panes.Add(ap);
}
I am trying to reach each buttons click event but don't know how to do it.
I have this method as for the click event to test a label inside the updatepanel but not working
protected void btn_Click(object sender, EventArgs e)
{
nameLabel.Text = "testinf";
}
this is my aspx page:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
<asp:Label ID="nameLabel" runat="server" Text="aa" />
<div style="overflow-x: auto;">
<asp:ListView ID="ListView1" runat="server" DataKeyNames="main_product_id" DataSourceID="odsMainProduct" OnSelectedIndexChanged="ListView1_SelectedIndexChanged">
<ItemTemplate>
<stackpanel orientation="Horizontal" />
<td>
<asp:LinkButton ID="lnkSelect" runat="server" CommandName="Select" Font-Overline="false" Font-Bold="true" Font-Size="15px" Height="30px" Text='<%# Eval("name") %>' />
<%--<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />--%></td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="color: white; text-align: left; width: auto">
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<td>
<asp:LinkButton ID="lnkSelect0" runat="server" CommandName="Select" Font-Overline="false" Font-Size="20px" ForeColor="red" Height="30px" Text='<%# Eval("name") %>' />
<%--<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />--%></td>
</SelectedItemTemplate>
</asp:ListView>
</div>
<asp:ObjectDataSource ID="odsMainProduct" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetMainProducts" TypeName="MainProductBLL"></asp:ObjectDataSource>
<asp:Accordion ID="accMenu" runat="server"></asp:Accordion>
</ContentTemplate>
</asp:UpdatePanel>
You need to store your button creation data in ViewState for creating these controls in page-load event, after that button click will be processed correct.
Order class should be marked as Serializable
public Order SelectedOrder
{
get
{
return ViewState["StoredOrder"] == null ? (Order)ViewState["StoredOrder"] : null;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (SelectedOrder != null)
{
PanelCreator(SelectedOrder);
}
}
protected void listviewselectedindexchanged(object sender, System.EventArgs e)
{
// I am not sure how you got order in this event, you should use your version of code, but idea is the same
ViewState["StoredOrder"] = sender as Order;
PanelCreator(SelectedOrder);
}
I have a nested repeater and I use a textbox in footer template. I wanto to get textbox.text value in button click. Here is my repeater:
<asp:Repeater ID="rprSSFirst" runat="server" OnItemDataBound="rprSSFirst_ItemDataBound" >
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
//******Some Items******
<asp:Repeater ID="rprSSNested" runat="server" > //Nested Repeater
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
//******Some Items******
</ItemTemplate>
<FooterTemplate>
<div style=" padding: 20px 35px;" id='ajax'>
<asp:TextBox ID="textbox" TextMode="MultiLine" Columns="50" Rows="10" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" OnClick="btn_Save_Click" Text="Save" />
</div>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
//In Code Behind
protected void btn_Save_Click(object sender, EventArgs e)
{
TextBox txtAns = (TextBox)rprSSFirst.Controls[rprSSFirst.Controls.Count - 1].FindControl("textbox");
}
But txtAns Value is always null. How to get footer item textbox value in button click? or any other way?
Thanks for your answers.
You have to find the nested RepeaterItem first where both controls are sitting. You can get it by casting the NamingContainer:
protected void btn_Save_Click(object sender, EventArgs e)
{
Button btnSave = (Button) sender;
RepeaterItem item = (RepeaterItem) btnSave.NamingContainer;
TextBox txtAns = (TextBox) item.FindControl("textbox");
}
You can use Commandname property like this for button of nested repeater:
<asp:Repeater ID="rprSSNested" runat="server" OnItemCommand="rprSSNested_ItemCommand" >
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
//******Some Items******
</ItemTemplate>
<FooterTemplate>
<div style=" padding: 20px 35px;" id='ajax'>
<asp:TextBox ID="textbox" TextMode="MultiLine" Columns="50" Rows="10" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Save" CommandName="cmd" CommandArgument="arg"/>
</div>
</FooterTemplate>
</asp:Repeater>
And add event in c# code like this:
protected void rprSSNested_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
if (e.CommandName == "cmd")
{
string ss = ((TextBox)e.Item.FindControl("textbox")).Text;
Response.Write(ss);
}
}
}
I have a repeater which is visible only by managers where they can accept/reject leave requests made by the users.
The following code while binding my repeater, retrieves if there are any employees on leave working in the same department and on the same date as the one requested by the user.
protected void RptLeaveRequests_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
otherEmpsLeave = new LeaveLogic().CheckEmployeeLeaveOnDateInSameDep(date, currEmp);
if (otherEmpsLeave != "")
{
//change border of repeater row to another colour and display otherEmpsLeave when manager hovers on repeater row
}
}
How can I change repeater row border colour (ex add a red border to make it stand out) and display otherEmpsLeave on hover?
ASP Repeater Code:
<h3>LEAVE REQUESTS</h3>
<asp:Label ID="LblNoRequests" Visible="false" Font-Size="14px" runat="server"></asp:Label>
<asp:HiddenField ID="dataGroups" runat="server" />
<asp:Repeater ID="RptLeaveRequests" runat="server"
onitemdatabound="RptLeaveRequests_ItemDataBound">
<ItemTemplate>
<table id="tableItem" runat="server">
<tr>
<td style="width:400px;">
<asp:Label ID="lblEmployeeId" runat="server" Text='<%#Eval("EmployeeId") %>' Visible="false" />
<asp:HiddenField ID="HdnEmployeeId" runat="server" Value='<%#Eval("EmployeeId") %>' />
<asp:Literal Text="" runat="server" ID="LiteralUser" ></asp:Literal>
</td>
</tr>
<tr>
<td style="width: 100px;">
<asp:HiddenField ID="HdnRequestId" runat="server" Value='<%#Eval("id") %>' />
<asp:Label ID="lblDate" runat="server" Text='<%#Eval("Date", "{0:dd/MM/yyyy}") %>'></asp:Label>
</td>
<td style="width: 80px;">
<asp:Label ID="lblHours" runat="server" Text='<%#Eval("Hours") %>'></asp:Label>
</td>
<td style="width: 50px; font-size:10px;">
<asp:Label ID="lblPeriod" runat="server" Text='<%#Eval("AMorPM") %>'></asp:Label>
</td>
<td style="width: 850px; font-size:10px;">
<asp:Label ID="lblNote" runat="server" Text='<%#Eval("Note") %>'></asp:Label>
</td>
<td style="width: 50px;">
<asp:RadioButtonList ID="rbtVerified" runat="server" Visible='<%#!(Boolean)Eval("ReadOnly") %>' >
<asp:ListItem Value="1">Accept</asp:ListItem>
<asp:ListItem Value="2">Reject</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:TextBox ID="txtNotes" runat="server" ></asp:TextBox>
</td>
</tr>
</table>
<div style="border-style: dotted; border-color:Black; width:100%; border-width:1px; border-color:#999999"></div>
</ItemTemplate>
</asp:Repeater>
From the MSDN example, something like
void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
// This event is raised for the header, the footer, separators, and items.
// Execute the following logic for Items and Alternating Items.
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
if (((Evaluation)e.Item.DataItem).Rating == "Good") {
((Label)e.Item.FindControl("RatingLabel")).Text= "<b>***Good***</b>";
}
}
}
instead of setting .Text set whatever property(s) you need, such as Background or Tooltip
On my aspx page i have a repeater with 5 textboxes with 1 imagebutton to edit the row
these textboxes are readonly, to edit them I need them to not be readOnly..
In my behind code i am using :
protected void EditRecipeInfo(object sender, CommandEventArgs e)
{
ImageButton ib = sender as ImageButton;
TextBox titleTXT = (TextBox)ib.FindControl("titleRepeat");
TextBox qtyTXT = (TextBox)ib.FindControl("qtyRepeat");
TextBox uomTXT = (TextBox)ib.FindControl("uomRepeat");
TextBox prepTXT = (TextBox)ib.FindControl("prepRepeat");
TextBox orTXT = (TextBox)ib.FindControl("orRepeat");
titleTXT.ReadOnly = false;
qtyTXT.ReadOnly = false;
uomTXT.ReadOnly = false;
prepTXT.ReadOnly = false;
orTXT.ReadOnly = false;
////
}
But when I fire this event the break points show me that the property is being set to false, but when I click to delete any value in the textbox it still acts like a readonly
UPDATE:
<asp:Repeater ID="ingredRepeater" runat="server">
<HeaderTemplate>
<table style="width: 100%">
<tr>
<th></th>
<th></th>
<th><h2>Title</h2></th>
<th><h2>Qty.</h2></th>
<th><h2>UoM</h2></th>
<th><h2>Prep.</h2></th>
<th><h2>Alternate</h2></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:ImageButton Style="height: 25px; width: 25px;" ImageUrl="/img/edit.png" Visible="true"
ID="editRecipeInfo" AutoPostBack="true" runat="server" OnCommand="EditRecipeInfo" CommandName='<%# DataBinder.Eval(Container, "DataItem.DetailID") %>' />
</td>
<td>
<asp:ImageButton ImageUrl="/img/RedX.png" ID="button2" runat="server" Height="20"
Width="20" CommandName='<%# DataBinder.Eval(Container, "DataItem.DetailID") %>'
OnCommand="deleteRecipeView" />
</td>
<td>
<asp:TextBox AutoPostBack="true" ReadOnly="true" ID="titleRepeat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>'
size="45" />
</td>
<td>
<asp:TextBox AutoPostBack="true" ReadOnly='true' ID="qtyRepeat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Quantity") %>'
size="10" />
</td>
<td>
<asp:TextBox AutoPostBack="true" ReadOnly='true' ID="uomRepeat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.UnitsOfMeasure") %>'
size="10" />
</td>
<td>
<asp:TextBox AutoPostBack="true" ReadOnly='true' ID="prepRepeat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Prep") %>'
size="10" />
</td>
<td>
<asp:TextBox AutoPostBack="true" ReadOnly='true' ID="orRepeat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AlternativeIngredients") %>'
size="20" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Make sure you're not re-binding the repeater after you set the ReadOnly property to true.
I agree with #Tariqulazam , the markup would help.
Assuming your code comes from an ItemCommand event handler, I am quite surprised to see the FindControl applied to the ImageButton.
I guess your code should be something like this :
void rpAcces_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//...
ImageButton ib = sender as ImageButton;
TextBox titleTXT = (TextBox)e.Item.FindControl("titleRepeat");
TextBox qtyTXT = (TextBox)e.Item.FindControl("qtyRepeat");
TextBox uomTXT = (TextBox)e.Item.FindControl("uomRepeat");
TextBox prepTXT = (TextBox)e.Item.FindControl("prepRepeat");
TextBox orTXT = (TextBox)e.Item.FindControl("orRepeat");
titleTXT.ReadOnly = false;
qtyTXT.ReadOnly = false;
uomTXT.ReadOnly = false;
prepTXT.ReadOnly = false;
orTXT.ReadOnly = false;
//...
}
Also, be aware that you can not rebind your repeater later in the page life-cycle without losing these changes.
And watch out for any Enabled attribute set on your TextBoxes
Once again, difficult to answer without the whole code.
I wrote a ASP.NET Application that get Data from the Active Directory. I use a ListView to display this data. The User input a String (Lastname or a part of this) in a TextBox. Than the ListView list all AD Users with the same string from the TextBox. Every Line get a Button "Anzeigen" to get more Informations about the User. This ListView has six columns and every line show a User. in column number six is the button "Anzeigen". If a User click on this button open a new WebForm "benutzer.aspx" with more Informations abaout this seleced User and get a Session Value "email" from the line.
My Problem:
I don't know how I get the Index of the Line of the ListView that I need for the Session Value.
My Code:
cs file:
protected void Button1_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Anzeigen")
{
//This give me everyone the Value -1 back
int selectedLine = myListView.SelectedIndex;
//I need the Line Index for the right Value
Label lb = (Label)myListView.Items[selectedLine].FindControl("Label2");
string email = lb.Text;
Session["email"] = email;
Response.Redirect("Benutzer.aspx");
}
}
ASPX File:
...
<ItemTemplate>
<tr runat="server">
<td align="left" ><asp:Label ID="Label1" Text='<%# Eval("Benutzer") %>' runat="server" /></td>
<td align="left"><asp:Label ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
<td align="left"><asp:Label ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
<td align="left"><asp:Label ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
<td align="left"><asp:Label ID="Label5" Text='<%# Eval("Telefon") %>' runat="server" /></td>
<td align="left"><asp:Button ID="Button1" Text="Anzeigen" OnCommand="Button1_Command" CommandName="Anzeigen" CommandArgument="myArgument" runat="server" /></td>
</tr>
</ItemTemplate>
...
I search and I found listview selectedindices but it don't work :( and I dont't can use it in my Application .
tarasov
Use ListView's ItemCommand rather than Button's on command
see http://www.codeproject.com/Articles/24570/Complete-ListView-in-ASP-NET-3-5
for more detail.
One more thing From example you can see that author has extracted the values from e.Item. You can pass the key(email,username or whatever) as CommandArgument and can access that value directly from command argument.
how to pass it
<asp:LinkButton ID="myLink" runat="server" CommandName="Anzeigen" CommandArgument='<%#Eval("KeyColumn")%>'>Anzeigen</asp:LinkButton>
Also use Linkbutton rather than Asp:Button
ASPX:
<td align="left"><asp:Button ID="Button1" Text="Anzeigen" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' runat="server" /></td>
CS:
protected void Button1_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument);
Label lb = (Label)myListView.Items[index].FindControl("Label2");
string email = lb.Text;
Session["email"] = email;
Response.Redirect("Benutzer.aspx");
}
}