problem with gridview method calling - asp.net

Though i am setting in grid view
OnRowDeleting="GridView1_RowDeleting"
and cicking on the gridview i am getting the
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
as i am clicking on Delete link it should open the Delete Event
protected void GridView1_RowDeleting(object sender,GridViewDeletedEventArgs e)
but its not opening,
please point me where is my mistake.

The problem is about your the event arguments, you should use GridViewDeleteEventArgs for OnRowDeleting. GridViewDeletedEventArgs is used for OnRowDeleted event.
protected void GridView1_RowDeleting(object sender,GridViewDeleteEventArgs e)
OnRowDeleting Reference
OnRowDeleted Reference
Hope this helps !

Related

Pass value from one xaml page to another xaml page in silverlight

Hello I am very new to Silverlight and I want to pass value from one Xaml page to another Xaml page in Silverlight. I got some solution for that as
protected void btn_click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Page1.xaml?key1"=txtname.Text, UriKind.Relative));
}
but I am finding an error in it as
An object reference is required for the non-static field, method, property System.Windows.Navigation.NavigationService.Navigate(System.Uri)'
Syntax issue. unless that is a typo
protected void btn_click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Page1.xaml?key1"=txtname.Text, UriKind.Relative));
}
should change to...
protected void btn_click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Page1.xaml?key1="+txtname.Text, UriKind.Relative));
}
Note the change from
"/Page1.xaml?key1"=txtname.Text
to
"/Page1.xaml?key1="+txtname.Text

How to know the previous event handled in asp.net

on page load i have shown data from database onto a gridview(with edit and delete option). I also have a search button on the page. when i click on search the searched data should be visible in the gridview, which is working fine. But when i click on delete link after search it does not take the searched row. The page postsback after clicking on delete. I need to check the event performed prior to event performed on gridview. How to do that?? I hope that the issue is clear.. Any help is appreciated. Thanks.
Page_Load occurs before RowCommand, are you only binding grid if(!IsPostBack) ?
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGrid();
}
}
protected void SearchButton_Click(object sender, EventArgs e)
{
BindGrid(searchText.Text);
}
protected void GridView_RowCommand(object sender, GridViewRowEventArgs e)
{
switch(e.CommandName)
{
case "Delete":
DeleteRow(e.Row.CommandArgument);
break;
}
}
private void BindGrid()
{
//GridView binding business logic.
}
private void BindGrid(String searchTerm)
{
//GridView binding logic with searchTerm.
}
private void DeleteRow(String commandArg)
{
//Convert command arg to ID or whatever and delete data.
}

How to get event in another control event?

In my application, i am trying to get button_click event in another button click event, but it is not working.
My code is,
protected void btn1_Click(object sender, EventArgs e)
{
Response.Write("hi.....");
}
protected void btn2_Click(object sender, EventArgs e)
{
btn1.Click += new EventHandler(this.btn1_Click);
}
What is wrong with this?
I suppose you want to call the code of btn1_click event.
If this is the case, you simple call it as a method in your btn2_Click.
protected void btn2_Click(object sender, EventArgs e)
{
btn1_Click (sender, e);
}

databound dropdownlist select an item

I have a databound dropdown list (ASP.net). I want the page to load with a certain item as the selected item.
I am not adding a blank first row (thats not what i need)
I find that I can get this to work with "AppendDataBoundItems" to true, but the side-effect is that I have all the items listed twice.
thanks for your help!
Use the Page_PreRender event to handle this situation....
In the Page_Load register an event handler for the PreRender event
protected void Page_Load(object sender, EventArgs e)
{
Page.PreRender += new EventHandler(Page_PreRender);
}
And in the PreRender event,
void Page_PreRender(object sender, EventArgs e)
{
ComboBoxSomething.SelectedValue = WhatEverYouWant;
}

Click event not work properly

In my website I wrote that code:
protected void Page_Load(object sender, EventArgs e){ LinkButton lbtnTopicAddress = new LinkButton(); lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;}
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e){ Server.Transfer("~/SpecificTopic.aspx)"
}
But when I press on the link in run time, the caller doesn't go to the EventHandler method.
Why?
Note,
I wrote code like that in many pages in the same website but it work only in one page.
i added that code to many page in website but it worded only in one page every page has its specific code and no relation between them I hope you understand me thanks
I need help pleaseeeeeeee..........................
Did you mean to miss off a ;and a } here?
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e){ Server.Transfer("~/SpecificTopic.aspx)"
I assume you've put a breakpoint in to ensure it isn't being fired?
I'm not exactly sure but I've got a feeling that instead of Page_Load you need to use Page_Init so your code would look this this:
protected void Page_Init(object sender, EventArgs e)
{
LinkButton lbtnTopicAddress = new LinkButton();
lbtnTopicAddress.Click += lbtnSpecificTopic1_Click;
}
protected void lbtnSpecificTopic1_Click(object sender, EventArgs e)
{
Server.Transfer("~/SpecificTopic.aspx");
}
p.s. 5 mins formatting your code can work wonders when trying to debug
Are you adding the button to the controls on your page, or are you trying to find the "lbtnTopicAddress" control on your page?
Simply declaring the button won't do anything -- you have to get a reference to the control itself from the page.

Resources