I have 2 aspx pages.. (view.aspx,edit.aspx).
under view.aspx I have grid which displays the following fields.
class,photo,photocaption,Edit which consists of class name, image of the class and a caption for the photo and a link button for edit which traverses to edit.aspx...
under edit.aspx, I have a table consisting of
Class(a drop down box),
Photo(text box with BROWSE button),
photocaption(Textbox).
when i click on the edit in view.aspx, I must get the entered values in the view.aspx grid by default in edit.aspx table..
Please help me to finish my Task...
Assuming your view.aspx page has a TextBox control for the class name called txtClassName, you can add a query string to your edit.aspx like this:
<asp:LinkButton ID="EditLink" runat="server" Text="Edit" PostBackUrl='<%# "edit.aspx?classname=" + txtClassName.Text %>' />
This creates the url in this format:
edit.aspx?classname=class1
Then, in the Page_Load event of your edit.aspx page, you can retrieve the selected class name like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string className = Request.QueryString["classname"];
// code to output the class details
// for example, if you want to add the class name to a dropdownlist:
DropDown1.Items.Add(className);
}
}
Related
I have designed the basic controls application in asp.net.---> Using the 3 controls are display the choosing controls.---->controls are added on the dropdownbox.-----> Values are enter the textbox.-----> Click to the button.
I have click the button is to show on the choosing controls are displayed it.
i had attached the snapshot.
enter image description here
If I get it correctly, you want to display appropriate asp.net control in a rectangle as displayed in the image?
Basically, I would go about it like this:
Add placeholder on main page. This placeholder will be used to store conrols.
Handle button click event in which you create desired controls and add them to placeholder
Main page addon:
<asp:Placeholder runat="server" ID="phControls"></asp:Placeholder>
and where button is, you need to add OnClick event handler
<asp:Button runat="server" ID="btnAddControl" ... OnClick="btnAddControl_Click"></asp:Button>
Main page code-behind:
...
protected void btnAddControl_Click(object sender, EventArgs e) {
if (myDropDown.SelectedValue == "TextBox") {
var tb = new TextBox();
tb.Text = tbEntry.Text;
phControls.Controls.Add(tb);
}
...
}
Something like that. Would prefer more information and some of your code though.
I have a FormView which I populate using SqlDataSource1. I do databinding like:
Text='<%# Bind("EffectiveDate") %>'
FormView also contain a dropdownlist with a custom SqldataSource2. Dropdown list contains list of cities. User is able to change a value in dropdown.
Once I submit a form I have to send to PowerShell script some parameters which I supposed to hide like street, ZipCode, etc... On first form load I can bind this parameters to hidden fields from SqlDataSource1. But if user change a value in dropdownlist I have to rebind parameters. Have no idea yet how.
Thanks!
You can configure the drop down list to do a post back.
AutoPostBack="true"
and then on Page Load or Selection changed event you can set up the hidden field.
Example:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
hfSomething.Value = ddlSomething.SelectedValue;
}
else
{
//data binding code
}
}
I currently have a listview on an ASP.NET webpage that displays "cottage" records from an Access database. The name of each cottage is displayed as a hyperlink so when clicked brings you to another webpage:
<li style="">Name:
<asp:Hyperlink ID="Cottage_NameLabel" NavigateURL="~/Cottage.aspx"
runat="server" Text='<%# Eval("Cottage_Name") %>' />
<br />
This works perfectly fine when selecting a hyperlink. What I want the system to do is to set the value of a publically declared variable (set in a module) to the Cottage_Name of the selected hyperlink. So say if i clicked on a hyperlink that said "cottage1", the public variable is set to "cottage1" and then the navigate URL opens the next webpage.
Would really appreciate it if anyone could help me do this!
Just use a LinkButton instead of a Hyperlink... Catch the click event and do whatever you want...
For instance:
<asp:LinkButton ID="Cottage_NameLabel" runat="server" Text="whatever" onclick="Cottage_NameLabel_Click" />
Then in CodeBehind:
protected void Cottage_NameLabel_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
Session["MyCottageName"] = btn.Text;
Response.Redirect("Cottage.aspx");
}
In your Cottage.Aspx page you can check the value of the Session variable like this:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["MyCottageName"] != null)
{
string name = (String)Session["MyCottageName"];
...
}
You can pass the name as a querystring variable to the page. If you go this route, you need to make sure you URL encode the cottage name:
<a href='/Cottage.aspx?name=<%# Server.UrlEncode(DataBinder.Eval(Container.DataItem, "Cottage_Name")) %>'><%# Eval("Cottage_Name") %></a>
And then on cottage.aspx you can get the cottage name:
Dim cottageName As String = Request.QueryString("name")
This would be preferable to a button or other postback solution as it removes the need for a postback and then a redirect.
I have a hyperlink in a gridview which I want users to click on and it directs them to a particular page and also either passes in the first field of the gridview (the ID) or holds it in session, preferebly in session.
The link is just static text so no matter what record they click on i want to get them to the same page, but with that records ID available.
Just not sure how to add this to the NavigateUrl of the hyperlink.
ANy hints appreciated, thanks
You can easily generate the URL in the markup of your GridView without resorting to code. What you need to do is:
In the DataNavigateUrlFields
property of your HyperLinkField, put
the name of the column that contains
your id.
In the
DataNavigateUrlFormatString, put the
path to your page, plus the
querystring that the next page will
use to get the id, but where the
value should go, put {0} instead.
e.g.
<asp:Hyperlink DataNavigateUrlFields="ProductId" DataNavigateUrlFormatString="details.aspx?id={0} />
When the control is rendered at runtime, you will find that for each row, the {0} is replaced by the value of the ProductId column.
See String.Format and DataNavigateUrlFormatString for more details.
You can handle the Row_DataBound event to find the hyperlink control and update the NavigateUrl property.
You can add simple html control Text to link, it will produce same html.
Use HyperLink control and then write an event handler function for RowDataBound event, like this:
protected void OnRowDataBound(object source, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hyperLink = e.Row.FindControl("hyperLinkID") as HyperLink;
// example, adjust this to your needs.
hyperLink.NavigateUrl = "~/detail.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "ID");
}
}
Not sure why you have taken server control instead of tag of HTML.
two ways you can do it.
1)if it is an static link just prefix the page name and append the id in mark up.
for ex
<a href='myPage.aspx<%#Eval("YourID")%>'><strong>Click me to navigate</strong></a>
2)give some id to the a tag and make it runat server handle the data bound event and bind the value to it.
protected void MyGridview_ItemDataBound(object sender, ListViewItemEventArgs e)
{
HtmlAnchor AncImage = e.Item.FindControl("AncImage") as HtmlAnchor;
AncImage.href="myPage.aspx"/id=" + DataBinder.Eval(e.Row.DataItem, "ID"); ;
//the id is the value that you want to append for redirection
}
I would like to use a TextBoxor Label (item) inside of a Gridview. When field is clicked, I would like to display list of records that contain:
- Item Name
- Description
- Price
- Image
- Add Button
It sounds to me like you are talking about having a "filter" option for your GridView.
If I'm reading your post correctly, you would like to be able to enter text into the TextBox and then filter the data within the GridView to show matching records. Below is some pseudo code that will hopefully help get you started...
FRONT END CODE
<asp:TextBox id="myBox" runat="server" OnTextChange="myBox_OnTextChange"></asp:TextBox>
<asp:GridView id="myGrid" runat="server">
//COLUMN 1
//COLUMN 2
//IMAGE TO ADD
</asp:GridView>
CODE BEHIND
//THIS CODE IS NOT CORRECT EXAMPLE ONLY TO GET YOU STARTED
protected void myBox_OnTextChange(EventArgs e)
{
if(!String.isNullorEmpty(this.myBox.Text))
{
//MyFunction will filter your datasource with the text box data and
//return a DataSet or DataTable or etc.....
this.myGrid.DataSource = MyFunction(myBox.Text);
this.myGrid.DataBind();
}
}