Hello guys i am using gridview ( from obout ) on my asp.net site. When the user clicks on Edit the griview opens up and shows a template for the clicked row. In there i got a save button. When the user clicks on it i got a simple JS script that pop ups a simple alert.
My problem is that now i need to show a different alert on different situations.
I tried putting this on the update event instead but it wont trigger :
Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopUpWindow", popupscript, False)
I am trying to find how can i have full control on the alert the user will see after the update event.
you can handle GridView's RowDataBound event,Try using this js function onclick
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// reference the Delete LinkButton
LinkButton db = (LinkButton)e.Row.Cells[3].Controls[0];
db.OnClientClick = "return confirm('Are you certain you want to delete this questionnaire?');";
}
}
(OR)
See HERE Example
Related
I have an update panel which refreshes a user control. The update panel is set to conditional, and the condition is on a textbox control. Using AsyncPostBackTrigger, to fire when the text changes in the textbox, it works fine. However, what I am not getting is when the page is first loaded, and the textbox is populated with data is that it is not firing the postback trigger.
Is there a way of forcing it fire when the page is loaded for the first time?
I have tried simple things such as UpdatePanel.Update(), or txtbox.text = string.empty to force it to recognise a change- but no luck.
Any ideas anyone?
Thanks
Please replace with your ids
private void tb_Loaded(object sender, RoutedEventArgs e)
{
TextStateChanged((TextBox)sender);
}
UpdateSite.txtPhone.Loaded += new RoutedEventHandler(tb_Loaded);
I'm registering a postback event for each row in an ASP.NET GridView.
protected void gvLRR_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
if (cs == null)
cs = Page.ClientScript;
e.Row.Attributes.Add("onclick",
cs.GetPostBackEventReference((GridView)sender, "Select$" + e.Row.RowIndex.ToString()));
}
}
The event that is called upon the user clicking a row is the SelectedIndexChanged of the GridView gvLRR.
PROBLEM:
All of this works just fine so long as I set the page directive EnableEventValidation to false, but if I do not set it to false then the page blows up when the user clicks on a row in the GridView. However, I see this as a bit of a hack, because I shouldn't have to disable event validation just to get postback events to work when clicking upon a GridView row. So is there a better way to go about doing this? Can I somehow register postback events for a row click and somehow manage to have event validation enabled still?
Thank you in advance for the help.
While searching the net, I found this ... click row on gridview and trigger postback c#
HTH :)
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 renew parameters of my DataSource for GridView on Button and loads event Page_Load()
and After it (or with it) GridView renews itself.
I need to rename Header rows but there is no event after Page Load.
more information about details here :
[On Button Click] I change DataSource and Bind it (SqlDataSource1.DataBind(); ) Then sure Page gone to Refresh elements.
[On Page_Load] GridView is changing data, but if I can't change Headers there because it's looking like loads after this function :(
[one more Button] I can add new button with a function - rename headers and it works correct everytime
protected void Button2_Click(object sender, EventArgs e)
{
// Stack overflow
DataRow T;
if (go)
if (GridView2.HeaderRow.Cells.Count != 0)
for (int i = 0; i < SQF.SQF.Permission.Rows.Count; i++)
{
T = SQF.SQF.Permission.Rows[i];
GridView2.HeaderRow.Cells[i].Text = (string)T["Caption1"];
WebMsgBox.Show((string)T["Caption1"]);
}
}
Trouble : I no need one more button for it, I need to rename header rows after I click button to change Data but I have no idea where I can do it.
thank you.
Well you could use Gridview DataBound event, like that:
<asp:GridView runat="server" ID="SomeID" OnDataBound="GridVIew_OnDataBound" ... />
The DataBound event occurs right after the databinding process for that particular control has completed.
After Page_Load there is an event Page.PreRender.
Maybe it will suit you.
EDIT.
All events of your components, such as GridView, are fired between Page.Load and Page.PreRender. Consider using RowDataBound and RowUpdated events.
I have a user control which contains a grid and three buttons for add,edit and delete.
I have placed this user control on an asp.net page.
I have OnClick events for these buttons.
When i click on add and delete buttons it's working fine but when i click on edit button,the onclick event of edit button is fired but the row in the grid doesn't appear in the edit mode, i have to click two times.
I don't know where is the problem.The onclick event handler for edit button is as follows:
protected void btnEditBankAccount_Click(object sender, EventArgs e)
{
grdBankAccounts.EditIndex = grdBankAccounts.SelectedIndex;
grdBankAccounts.RowSelectingEnabled = false;
}
Anyone please help.
my user control has a method which binds the grid to the data source, it's as follows
public void SetSupplierData(SupplierType Supplier)
{
if (Supplier != null)
{
ViewState["SupplierID"] = Supplier.SupplierId;
grdBankAccounts.DataSource = Supplier.BankAccounts;
grdBankAccounts.DataBind();
Session["BankAccounts"] = Supplier.BankAccounts;
}
}
the SetSupplierData method is called from the page where i have my user control.
In order to get this "in-place editing" in grids to work, I typically have to data-bind twice:
once in the OnInit or OnLoad method so that the button click event handlers have the data available to work on
in the OnPreRender method again to show the new values / new state (editing or not)
Marc