Set row height of gridview in webform when in edit mode - asp.net

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();
}

Related

how I find a control in datalist

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;
}
}

How can I sort a gridview when using custom header text?

I've got some custom header text that's being added on the 'RowCreated' event of my gridview:
protected void gvResults_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
LinkButton lbAptNo = new LinkButton();
lbAptNo.Text = "Apartment #";
lbAptNo.Click += new EventHandler(lbAptNo_Click);
e.Row.Cells[0].Controls.Add(lbAptNo);
}
}
protected void lbAptNo_Click(object sender, EventArgs e)
{
gvResults.Sort("aptno", SortDirection.Descending);
}
This code works fine in the sense that it adds the link button to the gridview and allows me to sort the data in descending order. However what I'm trying to do is detect what the current sorting is for that column, and then sort asc/desc depending on what the current value is.
I understand I can use GridView.SortDirection to get the direction of a column but there's no way for me to specify which column. How do I do this? Is there a way I can determine the sort direction of a particular column?
Thanks
You can use sortexpression property of gridview to sort on column.

checkbox.checked is always false in a grid view in IE

I have a checkbox inside a GridView. When i click on save button, i check at code behind which check boxes are checked to save the record in dbms. But Checkbox.checked property is always false.
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chbx = (CheckBox)row.FindControl("chk1");
if (chbx.Checked)
{
// ...
}
}
However it works fine in Mozilla but not in IE.
That's very rare that your server side code is working on one browser but not on another, But most common reason of this problem is that you might be binding your GridView in Page_Load without checking IsPostback property,
your code should be like this
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindYourGridView();// Bind your grid here only during first page load not every time
}

Show content in GridView footer in the Page_Load event method

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"];
}
}

GridView paging allowed but disabled, possible?

For a GridView, is there any way I can have AllowPaging="true" but have the pagination links disabled (still visible but not clickable)?
(It's for when the user decides to edit the GridView. In edit mode, Labels inside cells become TextBoxes.)
I've tried Enabled="false" but this disables everything, including the TextBoxes.
I suppose I could handle paging on the server side but I'd rather just disable the pagination links if it's possible.
Any ideas appreciated!
I would hide Pager on RowEditing and show it again on Cancel or Update:
void CustomerGridView_RowEditing(Object sender, GridViewEditEventArgs e)
{
// Hide the pager row.
CustomerGridView.PagerSettings.Visible = false;
}
void CustomerGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Cancel" || e.CommandName == "Update")
{
// Show the pager row.
CustomerGridView.PagerSettings.Visible = true;
}
}

Resources