Showing posts with label gridview. Show all posts
Showing posts with label gridview. Show all posts

Wednesday, March 28, 2012

the column size of gridview

hi all:

the one of the column of gridview got multiple line data to be shown , so
how do i deal with it? what i am thinking about is using template field
instead of the boundfield. is that other solution out there?

Cheers

NickHi Nick,

You can solve this problem with the DataGridView.AutoSizeColumns() method,
with one of the values from the DataGridViewAutoSizeColumnCriteria
enumeration.
You can choose to size columns based on the width of header text, the
currently displayed rows, or all the rows in the table.

The following code snippet resize columns based on the width of the largest
piece of text in a header or one of the rows for this column.
DataGridView1.AutoSizeColumns( _
DataGridViewAutoSizeColumnCriteria.HeaderAndRows)

Please note that this method needs to be invoked after you bind the data or
it won't have any effect. You might also want to use it after user editing
(perhaps in response to an event like DataGridView.CellValueChanged).

Rather than widening columns to fit, you can change the row size. By
default, the text in a column will wrap over multiple lines.

If you use the DataGridView.AutoSizeRows() method, the row will be
heightened to fit the content.

Before you use this method, you might want to widen the column size,
particularly if you have a field that contains a large amount of text. For
example, the following code snippet quadruples the size of the Description
column, and then resizes
the rows to accommodate the content.

DataGridView.Columns("Description").Width *= 4
DataGridView.AutoSizeRows( _
DataGridViewAutoSizeRowsMode.HeaderAndColumnsAllRo ws)

Pls let me know whether this helps you
Thanks & Regards,
Sundar Narasimman

"Nick" wrote:

Quote:

Originally Posted by

hi all:
>
the one of the column of gridview got multiple line data to be shown , so
how do i deal with it? what i am thinking about is using template field
instead of the boundfield. is that other solution out there?
>
Cheers
>
Nick

Thursday, March 22, 2012

The GridView 'GridView1' fired event Sorting which wasn't handled

Hi,
I get this error message when sorting a gridview:
The GridView 'GridView1' fired event Sorting which wasn't handled
What do I need to do?
Thanks!Hi,
you have AllowSorting="true" set for the GridView and therefore you need to
have event handler for its Sorting event
<asp:GridView AllowSorting=true ID="GridView1" runat="server"
OnSorting="GridView1_Sorting">
..
</asp:GridView>
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//...
}
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Arjen" <boah123@.hotmail.com> wrote in message
news:ddsgue$nbj$1@.news1.zwoll1.ov.home.nl...
> Hi,
> I get this error message when sorting a gridview:
> The GridView 'GridView1' fired event Sorting which wasn't handled
> What do I need to do?
> Thanks!
>
I tried, I don't get it to work.
I don't know what to add inside the GridView1_Sorting method.
I'm using the gridview with templatefields.
Can you help me?
Thanks!
"Teemu Keiski" <joteke@.aspalliance.com> schreef in bericht
news:epu6hdooFHA.1372@.TK2MSFTNGP10.phx.gbl...
> Hi,
> you have AllowSorting="true" set for the GridView and therefore you need
> to
> have event handler for its Sorting event
> <asp:GridView AllowSorting=true ID="GridView1" runat="server"
> OnSorting="GridView1_Sorting">
> ...
> </asp:GridView>
>
> protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
> {
> //...
> }
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
> "Arjen" <boah123@.hotmail.com> wrote in message
> news:ddsgue$nbj$1@.news1.zwoll1.ov.home.nl...
>

The GridView GridView1 fired event Sorting which wasnt handled

Hi,

I get this error message when sorting a gridview:
The GridView 'GridView1' fired event Sorting which wasn't handled

What do I need to do?

Thanks!Hi,

you have AllowSorting="true" set for the GridView and therefore you need to
have event handler for its Sorting event

<asp:GridView AllowSorting=true ID="GridView1" runat="server"
OnSorting="GridView1_Sorting">
...
</asp:GridView
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//...
}

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Arjen" <boah123@.hotmail.com> wrote in message
news:ddsgue$nbj$1@.news1.zwoll1.ov.home.nl...
> Hi,
> I get this error message when sorting a gridview:
> The GridView 'GridView1' fired event Sorting which wasn't handled
> What do I need to do?
> Thanks!
I tried, I don't get it to work.
I don't know what to add inside the GridView1_Sorting method.

I'm using the gridview with templatefields.

Can you help me?

Thanks!

"Teemu Keiski" <joteke@.aspalliance.com> schreef in bericht
news:epu6hdooFHA.1372@.TK2MSFTNGP10.phx.gbl...
> Hi,
> you have AllowSorting="true" set for the GridView and therefore you need
> to
> have event handler for its Sorting event
> <asp:GridView AllowSorting=true ID="GridView1" runat="server"
> OnSorting="GridView1_Sorting">
> ...
> </asp:GridView>
>
> protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
> {
> //...
> }
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
> "Arjen" <boah123@.hotmail.com> wrote in message
> news:ddsgue$nbj$1@.news1.zwoll1.ov.home.nl...
>> Hi,
>>
>> I get this error message when sorting a gridview:
>> The GridView 'GridView1' fired event Sorting which wasn't handled
>>
>> What do I need to do?
>>
>> Thanks!
>>
>>

Tuesday, March 13, 2012

the meaning of life and gridview's e.newValue

hey all,
what is the purpose of e.NewValues inside the GridView1_RowUpdating routine?
i've seen examples where you findControl then assign that value to
e.NewValues, but that seems like an extra step.
thanks,
rodchar"rodchar" <rodchar@.discussions.microsoft.com> wrote in message
news:355B7331-25E9-4E98-BDC7-A7D8D9BC0C52@.microsoft.com...
> hey all,
> what is the purpose of e.NewValues inside the GridView1_RowUpdating
routine?
> i've seen examples where you findControl then assign that value to
> e.NewValues, but that seems like an extra step.
> thanks,
> rodchar
I use is to validate serverside. Here is an example
Sub EmailGrid_Updating(sender as object, e as GridViewUpdateEventargs)
'Check format of new data
dim bCancel as boolean = false
msg1.text = string.empty
dim strEmailAddress as string = string.empty
if not e.newvalues(0) is nothing then
strEmailAddress = Server.htmlencode(e.newvalues(0).tostring())
end if
BCancel= Regex.IsMatch(strEmailAddress,
"^([\w-\.]+)@.((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-
Z]{2,4}|[0-9]{1,3})(\]?)$")
if BCancel then
dim strDate as string = string.empty
if not e.newvalues(2) is nothing then
strDate = Server.htmlencode(e.newvalues(2).tostring())
BCancel = IsDate(strDate)
if BCancel then
if (year(ctype(strDate,datetime)) < 2000) then
BCancel = false
end if
if not bCancel then msg1.text = "Invalid Date"
end if
else
msg1.text = "Invalid Email Address"
end if
e.Cancel = not bCancel
End sub
thank you i'll take a look.
"vMike" wrote:

> "rodchar" <rodchar@.discussions.microsoft.com> wrote in message
> news:355B7331-25E9-4E98-BDC7-A7D8D9BC0C52@.microsoft.com...
> routine?
> I use is to validate serverside. Here is an example
> Sub EmailGrid_Updating(sender as object, e as GridViewUpdateEventargs)
> 'Check format of new data
> dim bCancel as boolean = false
> msg1.text = string.empty
> dim strEmailAddress as string = string.empty
> if not e.newvalues(0) is nothing then
> strEmailAddress = Server.htmlencode(e.newvalues(0).tostring())
> end if
> BCancel= Regex.IsMatch(strEmailAddress,
> "^([\w-\.]+)@.((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-z
A-
> Z]{2,4}|[0-9]{1,3})(\]?)$")
> if BCancel then
> dim strDate as string = string.empty
> if not e.newvalues(2) is nothing then
> strDate = Server.htmlencode(e.newvalues(2).tostring())
> BCancel = IsDate(strDate)
> if BCancel then
> if (year(ctype(strDate,datetime)) < 2000) then
> BCancel = false
> end if
> if not bCancel then msg1.text = "Invalid Date"
> end if
> else
> msg1.text = "Invalid Email Address"
> end if
> e.Cancel = not bCancel
> End sub
>
>