Show content in GridView footer in the Page_Load event method - asp.net

I am getting Application name from querystring.
I have GridView control that I can use to insert some Tasks. I have to insert Tasks based on the Application name I am getting in the querystring. I am inserting Record in the GridView footer. Since, application name is coming from Querystring, I want to show it as one item in the GridView footer. How can I do this while Page_Loading time?
Thanks.

You will need to bind to the RowDataBound event and then check the event to see if it is the footer like so:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[0].Text = Request["ApplicationName"];
}
}

Related

Hide databound RadGrid rows

I have a telerik radgrid in my .aspx page name rgLowRise, and I have an ObjectDataSource as the DataSource set like rgLowRise.DataSourceID = odsLowRise. This works fine, but I want it not to show any records at first load, how can I do that? And I have to use DataSourceID and not DataSource due to some reasons.
Thanks
You can remove the DataSourceID from the markup or your code behind (Page_Load) and set at a later stage, e.g. Button_Click or some other event
protected void Button_Click(object sender, EventArgs e)
{
rgLowRise.DataSourceID = odsLowRise; //until you click this button, the grid would display nothing
}

Conditionally Populate GridView

I have an asp:GridView tied to an asp:SqlDataSource that gets populated after the user clicks a button in the UI.
For security, I do not want the GridView to populate unless some business logic checks succeed first.
What is the proper way to accomplish this?
The proper way would be to do it on Code Behind. Don't set the DataSource in the mark up and just assign the Datasource on code behind after you have executed your business logic and verify that it should populate the grid:
protected void button_click(object sender, EventArgs e)
{
if(validateBusinessRules())
{
gridview1.DataSource=SqlDataSource2;
gridview1.DataBind();
}
}

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.

ASP.Net - Gridview row selection and effects

I'm using the following code in attempt to allow the user to select a gridview row by clicking anywhere on the row (plus mouse over and out) effects. The code doesn't seem to be applied on rowdatabound and I can't break into the event. (It is wired).
The control is in a usercontrol, that lives in a content page, which has a masterpage.
protected void gvOrderTypes_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView gvOrdTypes = (GridView)sender;
//check the item being bound is actually a DataRow, if it is,
//wire up the required html events and attach the relevant JavaScripts
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvOrdTypes, "Select$" + e.Row.RowIndex);
}
}
Scratch that. The handler was wired to the databound event instead of rowdatabound. Sorry everyone. As a side note, the code works

hide delete button in list page in dynamic data

I am using Asp.Net Dynamic Data. I want to remove delete button from List and details page. I dont want to remove it from mark up. Is there any way to remove delete button based on entity and without adding custom pages?
Hi I was able to do it with this code.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton delete = (LinkButton) e.Row.FindControl("DeleteLinkButton");
delete.Visible = false;
}
}
Try Creating a custom page and you will have all control over default pages template. Look following video explains how to do it.
http://www.asp.net/web-forms/videos/aspnet-dynamic-data/how-do-i-make-custom-pages

Resources