I have one listview that compiles layout template, item template and insert item template. Rest is working fine except insert item template hide/show functionality. I have a requirement to hide or show the insert item template, what i have tried till now is..i took one asp button and wrote the following line on click event.
lvwCustomers.InsertItemPosition = InsertItemPosition.None
It does nothing on the first click but it disables the insert item template on the second click and after that my submit button gives object reference exception.
Any Help.
Like this?
protected void Button1_Click(object sender, EventArgs e)
{
ListView1.InsertItem.Visible = false;
}
Related
Asp button click does not fire. I wrote Response.Write("404.aspx"); in to button click event in codebehind. But it does not fire. Here is the page with a fire problem button:
please click here
thanks.
Here is the code behind:
protected void bntTest_Click(object sender, EventArgs e)
{
Response.Redirect("404.aspx");
}
protected void btn2_Click(object sender, EventArgs e)
{
Response.Redirect("404.aspx");
}
It does not work because your submit button is not inside the form tag so it won't be able to post the submitted data and the same time, the click event will not fire as the page does not post, you can see below:
EDIT:
You have added a nested form tag that you can not because form tag can not be nested within another form tag. So just remove the nested form tag and it will work.
Try to restructure your project using these guidelines:
Only add form elements to aspx pages
Add main content to MasterPage from pages
Add any content that needs to be nested within a form to a UserControl that is placed within a page.
I added controls (i.e. template column) dynamically in grid view and click on button (post back) then grid view populated existing data (i.e.posted data) twice separated by
protected void Page_Init(object sender, EventArgs e)
{
//on init recreated controls
// if (IsPostBack)
{
gvFirst.DataSource = GetData("select top 10 * from Project_Master");
gvFirst.DataBind();
}
}
Sounds like you might be using Auto-generated fields. In design view, click the smart tag on the gridview and click "edit columns." Then uncheck the checkbox that says "Auto-generate fields." I think this should fix your problem if I am understanding you correctly.
I have used jQuery in my website. I have a navigation bar in my header. When user clicks any link given in my menu bar. It calls my javascript function..and a dialog box appears having a form. For example I have a form say "Add Country". When user clicks the link "Add country"
A form appears in a dialog box. And then user will be able to add country in the given form.
Now i have a gridview in my page..where im managing my data. My country table has 3 coloumns. Coutry Code, Country Name, Description. I have bound country table as sql datasource with that gridview. I have added a asp button as a template item in that gridview as well. All i want to do is..When user clicks the edit button of the particular row in my grid view..i would get the countryID of that row. And i want to call that country FORM again..where user will be able to edit. How can i call my java script function in c# code so that i would be able to call that form again ? I m relatively a new programmer. Anmy detailed guidance will be highly appreciated.
Lets suppose i have :
protected void EditSeriesButton(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
int countryID =Convert.ToInt32(CountryGridView.DataKeys[row.RowIndex].Value);
//Here i have got the id of that row. Now i want to call the function of my
//javascript so that i can call my country form.
//Just please guide me how to call javascript function here to open my
// dialog box.
//i will do rest of the things.
}
Please help me as soon as possible!!
Regards,
You can use gridview's rowdatabound event to add a onclick attribute to that button to call the javascript function:
protected void CountryGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int countryID = Convert.ToInt32(CountryGridView.DataKeys[e.Row.RowIndex].Value);
Button btnButton = (Button)e.Row.FindControl("btnName");
btnButton.OnClientClick = "return Dosomething('"+countryID+"');";
}
}
I am using a modular popup to show gridview in a popup. Now I want to implement paging of this gridview. When I click on the page number the popup disappears. How do I avoid it? I want it to disappear only when clicking close button.
I assume that you're using the ModalPopupExtender from the AjaxControlToolkit.
If you're posting back you always need to call ModalPopupExtender1.Show() in codebehind when you want it to stay visible.
You could simplify it by using Page_PreRender if you have many events and you don't want to remember this always:
protected void Page_PreRender(object sender, System.EventArgs e)
{
// change "this" to somewhat appropriate for example your GridView
// "this" makes sense for example in a UserControl
if (this.Visible) {
this.ModalPopupExtender1.Show();
}
}
I have a control placed in edit item template in detail view control. what ever the control I am using I need to access those values in my code behind page that in my item updating event
Can any one tel me the syntax how to acces it those control values?
Actually what ever control are there in my edit item template are not added in my designer.cs file what is the issue for this
thank you
this will definitly work try..
protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
TextBox txtbox = (TextBox)DetailsView1.FindControl("YourControlID");
}