how I find a control in datalist - asp.net

I have taken a datalist in my asp.net project which contains some picture and picture name. Now I want to show each picture in another page after. It means if any user will click on the picture then picture will open with it's details in another page.So I want to know that how I find a control in datalist.
In following picture of datalist I want to click on picture name like Jai Ho and It will open in another page.

You can use the OnClientClick property of Link Button.
In <asp:LinkButton> tag add following code
OnClientClick="javascript:window.open('your_url');"

try this
protected void up-movie-name_Click(object sender, EventArgs e)
{
Label4.Text = (Datalist1.SelectedItem.FindControl("Label1").ToString());
}
or
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
LinkButton linkButton = e.Item.FindControl("LinkButton1") as LinkButton;
string commandText = linkButton.Text;
}
}

Related

How to add Data From a combobox to a gridview control

I want To add The selected product from the Combo box to the grid view.
I have tried it by adding it in list box and it did work but to be more flexible with it I want to try grid view
protected void Button1_Click(object sender, EventArgs e)
{
lbl.Text = Billing.SelectedItem.Text;
Get.Items.Add(Billing.SelectedItem.Text);
Billing.Focus();
}
I have used this code to add it in the listbox.. And now for more flexibility I want it to do with gridview.

How to call method on text box change event

I have an Id in textbox and I want on behalf of id ,name should be displayed in an below another textbox.I have created an method but don't know where to call it..
Whenever I select the id,the below textbox should automatically be filled with an name of that particular Id..
Please Help me...
You can use code like this:(Double click on textbox at design view)
void textBox1_TextChanged(object sender, EventArgs e)
{
PopulateGrid(textBox1.Text);
}
void PopulateGrid(string queryStr)
{
//here you can write the binding code
}

Get asp.net button html

I have mostly worked with MVC but now doung a project in asp.net. I can't figure out how to render an anchor button, link button or whatever from code behind in a block of text. This button will do postback.
Example: The following errors occured, Click Here.
How do you get the html of that button and append it to the text?
You can add a button to placeholder, like this:
In markup, add this:
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
In code, add this:
protected void Page_Load(object sender, EventArgs e)
{
Button btn = new Button();
btn.ID = "myButton";
btn.Text = "Dynamic Button";
btn.UseSubmitBehavior = true;
btn.Click += new EventHandler(myButton_Click);
PlaceHolder1.Controls.Add(btn);
}
And access the button's click event :
protected void myButton_Click(object sender, EventArgs e)
{
// Do whatever you need
}
NOTE: You have to recreate all dynamically created controls after postback! In this example code to create the button is placed in Page_Load so that it will be recreated at each postback.

Set row height of gridview in webform when in edit mode

I have a gridview that I need to use to edit and update a table in SQL. I have the gridview, the edit, update and cancel functionality all set. My problem is that when the user selects the edit function, the row height drops to a single line. Unfortunately, the cells that need to be updated are comment fields so there can be more than one line of information. What I would like to do is change the edit mode to resize the row height so the user can see the entire cell contents. I have tried the DataGridView.AutoSizeRowsMode but this only applies to a windows form not a webform.
I am using Visual Web Developer, SQL2008R2 and asp.net
In the GridView_RowDataBound you can check the row being edited and set it's height:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex == GridView1.EditIndex)
{
e.Row.Height = 340;
}
}
Assuming that you have something like this in RowEditing:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindGridView();
}

How to access Repeater FooterTemplate TextBox?

What I am trying to do is to access the value from the TextBox1 to display back on the screen.
I tried to access it from the Page_Load() and the OnItemDataBound and they both failed.
It seem like the code is able to access the control but it return nothing back.
protected void Page_Load(object sender, EventArgs e)
{
Literal Literal1 = (Literal)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("Literal1");
Response.Write(Literal1.Text);
//this techique is not working for the line below
TextBox TextBox1 = (TextBox)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("TextBox1");
Response.Write(TextBox1.Text);
}
public void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//this techique is not working
if (e.Item.ItemType == ListItemType.Footer)
{
TextBox TextBox1 = (TextBox)e.Item.FindControl("TextBox1");
Response.Write(TextBox1.Text);
}
}
I'm not sure what you mean by "they both failed" but if the Text property of the Textbox is empty i might be because you are rebinding your repeater on each post back. Try wrapping your repeater .DataBind() with a !IsPostBack condition.
I have to use "Literal" as an alternate solution by passing the html Textbox problem. I do not like this solution but i guess i have to use it.

Resources