Showing posts with label datagrid. Show all posts
Showing posts with label datagrid. Show all posts

Saturday, March 31, 2012

Triggering ItemCommand with ImageButton in Datagrid

Hi

I had a Delete Column in a datagrid that was a Linkbutton. That needed to
change into a ImageButton because of the design demands in the project. Then
how do I trigger the DeleteCommand with that button?

I don't want to have to add a AddHandler in the ItemCreated or ItemDataBound
for this ImageButton cause then I can't get the ID from the Row to delete as
easy...

please help/
Lars NetzelSpecify the ImageButton with CommandName="Delete" attribute.

<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../
CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
and Update correspond to the same action with the DataGrid (DataGrid has
these command names predefined for cthese actions)

See docs for further details.

--
Teemu Keiski
ASP.NET MVP, Finland

"Lars Netzel" <uihsdf@.adf.se> wrote in message
news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Hi
> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
> change into a ImageButton because of the design demands in the project.
> Then how do I trigger the DeleteCommand with that button?
> I don't want to have to add a AddHandler in the ItemCreated or
> ItemDataBound for this ImageButton cause then I can't get the ID from the
> Row to delete as easy...
> please help/
> Lars Netzel
Ah, stupid me:) I wrote ItemCommand instead of CommandName... thx

/Lars

"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:eHCfx26LFHA.3988@.tk2msftngp13.phx.gbl...
> Specify the ImageButton with CommandName="Delete" attribute.
> <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
> CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
> and Update correspond to the same action with the DataGrid (DataGrid has
> these command names predefined for cthese actions)
> See docs for further details.
> --
> Teemu Keiski
> ASP.NET MVP, Finland
> "Lars Netzel" <uihsdf@.adf.se> wrote in message
> news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
>> Hi
>>
>> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
>> change into a ImageButton because of the design demands in the project.
>> Then how do I trigger the DeleteCommand with that button?
>>
>> I don't want to have to add a AddHandler in the ItemCreated or
>> ItemDataBound for this ImageButton cause then I can't get the ID from the
>> Row to delete as easy...
>>
>> please help/
>> Lars Netzel
>>

Triggering ItemCommand with ImageButton in Datagrid

Hi
I had a Delete Column in a datagrid that was a Linkbutton. That needed to
change into a ImageButton because of the design demands in the project. Then
how do I trigger the DeleteCommand with that button?
I don't want to have to add a AddHandler in the ItemCreated or ItemDataBound
for this ImageButton cause then I can't get the ID from the Row to delete as
easy...
please help/
Lars NetzelSpecify the ImageButton with CommandName="Delete" attribute.
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
and Update correspond to the same action with the DataGrid (DataGrid has
these command names predefined for cthese actions)
See docs for further details.
Teemu Keiski
ASP.NET MVP, Finland
"Lars Netzel" <uihsdf@.adf.se> wrote in message
news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Hi
> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
> change into a ImageButton because of the design demands in the project.
> Then how do I trigger the DeleteCommand with that button?
> I don't want to have to add a AddHandler in the ItemCreated or
> ItemDataBound for this ImageButton cause then I can't get the ID from the
> Row to delete as easy...
> please help/
> Lars Netzel
>
Ah, stupid me:) I wrote ItemCommand instead of CommandName... thx
/Lars
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:eHCfx26LFHA.3988@.tk2msftngp13.phx.gbl...
> Specify the ImageButton with CommandName="Delete" attribute.
> <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
> CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
> and Update correspond to the same action with the DataGrid (DataGrid has
> these command names predefined for cthese actions)
> See docs for further details.
> --
> Teemu Keiski
> ASP.NET MVP, Finland
> "Lars Netzel" <uihsdf@.adf.se> wrote in message
> news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
>

trim a URL link through datagrid

Hi,

Is there anyway I can trim this URL?

The Output is something like this:http://www.test.com/default.aspx?siteid=1&pagetitle=this_is_a_test and I want to get rid of everything past "?" so it just showshttp://www.test.com/default.aspx

This is the code i am using to get the URL through a datagrid in C#: 'Navigate='<%# Databinder.Eval(Container.DataItem, "LinkPath") %>' How can I trim this URL in the backend?

Thanks for anyone that can help me out.

Hi

Hope this helps

//Create a method calledstring GetTrimmedURL(string CompleteURL){ string TrimmedURL = String.Empty; string str = CompleteURL;int intIndexOfchar = str.IndexOf("?"); TrimmedURL = str.substring(intIndexOfchar, (str.Length() - intIndexOfchar));return TrimmedURL;}

Call this method at the place where you are doing the data binding. Say something like

'Navigate='<%# GetTrimmedURL(Databinder.Eval(Container.DataItem, "LinkPath")) %>'

Please note that this trims from the first instance of question mark though.

Hope this helps

Note: Pls watch out for small syntactical errors. Did this on a notepad.

VJ


Hi

You can do the following to strip the querystring off the URL:

Uri linkPath =new Uri(YOUROBJECTHERE.LinkPath);string newLinkPath = linkPath.Scheme + "://" + linkPath.Host + linkPath.AbsolutePath;

You could either do this is in the class you are databinding to, or perhaps in an OnItemDataBound event handler on your DataGrid, depending on your preference.

Hope this helps.

Seb

Trim string to fit in fixed width Table Cell [Edited by Adec, moderator]

I have the following BIG problemSmile [:)]
The column of datagrid is bind to a database field.
If lenght of string is bigger than the column width i want to trim the string.
No metter if the trimmed word has sense.
I would like to know if anyone knows if there is a way to calculate
string width in pixel in connection to font size used in that particular cell.
You can check the string size and do what you need to with it in your DataGridItemCreated event handler.
that's ok for the position where check, but the problem is how measure the width in pixel of the string:-)
Your getting confused, and making this to complicated. You dont measure strings in pixels, you measure strings in Charatchers, figure out how many charatchers will fit in the column of your datagrid, and trim the string to that amount of chars, I would recomend trimming it to 3 less chars than will fit and appending on a ... so that users know it's been trimmed.
Remember, capital letters take up more space than lower case ones, and different ascii chars can take up a space and a half in some cases purley literally speaking, like the @. symbol.

I would suggest you use sql to get the substring - select substring(myfield, 1, 10) as myfield from my table. This gets the first 10 characters. To add the "..." then select substring(myfield, 1, 7)+'...' as myfield from my table


It is ok, i will follow your indication. But still look for a method like TextWidth("...") to use in application.
Thanks. Best Regards

Wednesday, March 28, 2012

Trimming text returned from db

Hi

In my App I have a datagrid with a template column. In my DB I have a field called "Bio" wich holds user biographies. The idea is that within the datagrid only a small portion of the bio is shown and visitors click onto detail pages to see photgraphs and full information. Is there a way to limit the output from the Bio field to say 100 characters

Thanks

hpYou could limit the size of what you display in your datagrid column for Bio through many ways. One of those is to limit what you fetch from the database using LEFT(Bio,100) in your SQL statement.

You could equally use a bound column. This is what MSDN has to say on that:

"A bound column (BoundColumn element) displays information from one column of a data source. You typically add one bound column to the grid for every data column you want to display. Use bound columns when you want to choose which data columns to display in the grid. Bound columns also allow you to set a variety of properties to specify features such as:

The text, font, and color of the column header and footer.
Column width.
Data format.

Whether the column is read-only (that is, whether it will display an editable control when the row is in edit mode).
For details on creating bound columns in the Visual Studio Web Forms Designer, see Adding Bound Columns to a DataGrid Web Server Control. For details on creating bound columns, see DataGrid Web Server Control."

You should be able to combine both approaches to evolve something nice.
In addition if you need the full bio from the db to use later one (perhaps they can vie the full bio via a link or something), you may want to just limit it on the front end. To do this you could use the ItemDataBound of the datagrid. If the value is stored in a control such as a lable you would use FindControl and then set the value. Something like this...

Label lblTemp = (Label)e.Item.FindControl("lblBio");
if (lblTemp != null)
lblTemp = lblTemp.Text.Substring(1, 100);

May not be completely accurate but it should get you on the right path.
Excellent, Many thanks

trimming text in a datagrid to match column length

I have a messaging application that has a data grid with information like an
email list would have (from, subject, time sent, size) but the subject
could be very long in theory, and then it would word wrap.. the subject is a
variable width column (resizes to fit space) while the others are fixed
size... the problem is that i dont want the text to ever word wrap.. but
truncate the visible subject to match the current cell width... (kinda like
gmail does) how would i go about doing this at runtime on the client's page?
thanks!I guess there are a couple of ways that I can think of to fix this. The fir
st and easiest way could be to only return a certain number of characters fr
om the query of stored procedure. For example:
select substring(subject, 0, 10) from emaillist
that way the query will do all the work.
Now another example could be to do it within the code, for example:
<ItemTemplate>
<%# TrimSubject(DataBinder.Eval(Container.DataItem, "Subject")) %>
</ItemTemplate>
public string TrimSubject(string subject)
{
string retVal = subject;
if(retVal.Length>100)
{
retVal = retVal.Substring(0, 100) + "...";
}
return retVal;
}
Hope those examples help.
Alan Washington
http://www.aewnet.com

> I have a messaging application that has a data grid with information like
an
> email list would have (from, subject, time sent, size) but the subject
> could be very long in theory, and then it would word wrap.. the subject is
a
> variable width column (resizes to fit space) while the others are fixed
> size... the problem is that i dont want the text to ever word wrap.. but
> truncate the visible subject to match the current cell width... (kinda lik
e
> gmail does) how would i go about doing this at runtime on the client's pag
e?
> thanks!
>
>
User submitted from AEWNET (http://www.aewnet.com/)
You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
this. Hope this helps!
Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com
Imports System.Drawing
Public Function MeasureString(ByVal Value As String, ByVal Font As
Drawing.Font) As SizeF
' Set up string.
Dim oBitMap As New Bitmap(1, 1)
Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)
' Measure string.
Dim Size As New SizeF
Size = oGraphics.MeasureString(Value, Font)
Return Size
End Function
Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
As Single, ByVal Font As Drawing.Font) As String
Dim sReturn As String
If MeasureString(Value, Font).Width < MaxSizeF Then
sReturn = Value
Else
sReturn = Value
Dim i As Integer
Do While MeasureString(Value.Substring(0, Value.Length - i) &
"...", Font).Width > MaxSizeF
i += 1
Loop
sReturn = Value.Substring(0, Value.Length - i) & "..."
End If
Return sReturn
End Function
....
ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS THE
LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
LONGEST EVER", 300, New Font(New
System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
GDI+ on asp.net on the client side? doesn't sound right, because the user
could resize the window thus changing the size of the column the text is in.
"Joel Cade" <joel@.nospam.figtreesolutions.com> wrote in message
news:0F697488-C620-4C51-80EB-803D11AF5D0C@.microsoft.com...
> You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
> this. Hope this helps!
> Joel Cade, MCSD
> Fig Tree Solutions, LLC
> http://www.figtreesolutions.com
> Imports System.Drawing
> Public Function MeasureString(ByVal Value As String, ByVal Font As
> Drawing.Font) As SizeF
> ' Set up string.
> Dim oBitMap As New Bitmap(1, 1)
> Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)
> ' Measure string.
> Dim Size As New SizeF
> Size = oGraphics.MeasureString(Value, Font)
> Return Size
> End Function
> Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
> As Single, ByVal Font As Drawing.Font) As String
> Dim sReturn As String
> If MeasureString(Value, Font).Width < MaxSizeF Then
> sReturn = Value
> Else
> sReturn = Value
> Dim i As Integer
> Do While MeasureString(Value.Substring(0, Value.Length - i) &
> "...", Font).Width > MaxSizeF
> i += 1
> Loop
> sReturn = Value.Substring(0, Value.Length - i) & "..."
> End If
> Return sReturn
> End Function
> ....
> ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS
> THE
> LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
> LONGEST EVER", 300, New Font(New
> System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
>
Hi Brian,
As for the truncating string values in DataGrid Cell(Table cell), I think
generally we have two means:
1. Truncating the string's length at serverside when we retrieve it from db
or output into the page via code. Just as the other members have suggested.
But this will make the output string's length be a fixed size.
#Creating a Custom DataGridColumn Class, Part 2
http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx
2. Using css style on the output <table> and the text content in table
cell. There is one css attribute named
"OVERFLOW", it can be applied on <div> or <p> ... and when we set the
"OVERFLOW:Hidden", it will truncat the exceeded content according to the
container element's width.
#overflow Attribute | overflow Property
http://msdn.microsoft.com/library/d...uthor/dhtml/ref
erence/properties/overflow.asp
For example:
<p style="OVERFLOW:hidden;WIDTH:100">
<% Response.Write(new String('d',1000)); %>
</p>
Also, since in our problem, we need to set the datagrid column's width
unfixed, so we also need to make the with of the <p> as a relative size.
After some testing, it seems that we also have to assign the "table-layout
: fixed" css attribute to the DataGrid(<table> ). Here is some demo code on
applying the styles on datagrid:
<asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Column1"
HeaderText="Column1"></asp:BoundColumn>
<asp:BoundColumn DataField="Column2"
HeaderText="Column2"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Column3">
<ItemTemplate>
<p style="OVERFLOW:hidden;WIDTH:90%">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Column3") %>'>
</p>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
=======================
In our code-behind , we can use the following code (in Page_load) to apply
the "table-layout" style on datagrid:
private void Page_Load(object sender, System.EventArgs e)
{
...............
dgStyle.Style["TABLE-LAYOUT"] = "fixed";
}
Hope these help. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
thanks that worked perfectly!
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:%23bjDCLxtEHA.3696@.cpmsftngxa10.phx.gbl...
> Hi Brian,
> As for the truncating string values in DataGrid Cell(Table cell), I think
> generally we have two means:
> 1. Truncating the string's length at serverside when we retrieve it from
> db
> or output into the page via code. Just as the other members have
> suggested.
> But this will make the output string's length be a fixed size.
> #Creating a Custom DataGridColumn Class, Part 2
> http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx
> 2. Using css style on the output <table> and the text content in table
> cell. There is one css attribute named
> "OVERFLOW", it can be applied on <div> or <p> ... and when we set the
> "OVERFLOW:Hidden", it will truncat the exceeded content according to the
> container element's width.
> #overflow Attribute | overflow Property
> [url]http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/ref[/ur
l]
> erence/properties/overflow.asp
> For example:
> <p style="OVERFLOW:hidden;WIDTH:100">
> <% Response.Write(new String('d',1000)); %>
> </p>
> Also, since in our problem, we need to set the datagrid column's width
> unfixed, so we also need to make the with of the <p> as a relative size.
> After some testing, it seems that we also have to assign the "table-layout
> : fixed" css attribute to the DataGrid(<table> ). Here is some demo code
> on
> applying the styles on datagrid:
> <asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
> <Columns>
> <asp:BoundColumn DataField="Column1"
> HeaderText="Column1"></asp:BoundColumn>
> <asp:BoundColumn DataField="Column2"
> HeaderText="Column2"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Column3">
> <ItemTemplate>
> <p style="OVERFLOW:hidden;WIDTH:90%">
> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
> "DataItem.Column3") %>'>
> </p>
> </asp:Label>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> =======================
> In our code-behind , we can use the following code (in Page_load) to apply
> the "table-layout" style on datagrid:
> private void Page_Load(object sender, System.EventArgs e)
> {
> ...............
> dgStyle.Style["TABLE-LAYOUT"] = "fixed";
> }
>
> Hope these help. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>

trimming text in a datagrid to match column length

I have a messaging application that has a data grid with information like an
email list would have (from, subject, time sent, size) but the subject
could be very long in theory, and then it would word wrap.. the subject is a
variable width column (resizes to fit space) while the others are fixed
size... the problem is that i dont want the text to ever word wrap.. but
truncate the visible subject to match the current cell width... (kinda like
gmail does) how would i go about doing this at runtime on the client's page?
thanks!I guess there are a couple of ways that I can think of to fix this. The first and easiest way could be to only return a certain number of characters from the query of stored procedure. For example:

select substring(subject, 0, 10) from emaillist

that way the query will do all the work.

Now another example could be to do it within the code, for example:

<ItemTemplate>
<%# TrimSubject(DataBinder.Eval(Container.DataItem, "Subject")) %>
</ItemTemplate
public string TrimSubject(string subject)
{
string retVal = subject;
if(retVal.Length>100)
{
retVal = retVal.Substring(0, 100) + "...";
}

return retVal;
}

Hope those examples help.

Alan Washington
http://www.aewnet.com

> I have a messaging application that has a data grid with information like an
> email list would have (from, subject, time sent, size) but the subject
> could be very long in theory, and then it would word wrap.. the subject is a
> variable width column (resizes to fit space) while the others are fixed
> size... the problem is that i dont want the text to ever word wrap.. but
> truncate the visible subject to match the current cell width... (kinda like
> gmail does) how would i go about doing this at runtime on the client's page?
> thanks!

User submitted from AEWNET (http://www.aewnet.com/)
You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
this. Hope this helps!

Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com

Imports System.Drawing

Public Function MeasureString(ByVal Value As String, ByVal Font As
Drawing.Font) As SizeF
' Set up string.
Dim oBitMap As New Bitmap(1, 1)
Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)

' Measure string.
Dim Size As New SizeF
Size = oGraphics.MeasureString(Value, Font)

Return Size
End Function

Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
As Single, ByVal Font As Drawing.Font) As String
Dim sReturn As String

If MeasureString(Value, Font).Width < MaxSizeF Then
sReturn = Value
Else
sReturn = Value

Dim i As Integer

Do While MeasureString(Value.Substring(0, Value.Length - i) &
"...", Font).Width > MaxSizeF
i += 1
Loop

sReturn = Value.Substring(0, Value.Length - i) & "..."
End If

Return sReturn
End Function

.....

ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS THE
LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
LONGEST EVER", 300, New Font(New
System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
GDI+ on asp.net on the client side? doesn't sound right, because the user
could resize the window thus changing the size of the column the text is in.

"Joel Cade" <joel@.nospam.figtreesolutions.com> wrote in message
news:0F697488-C620-4C51-80EB-803D11AF5D0C@.microsoft.com...
> You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
> this. Hope this helps!
> Joel Cade, MCSD
> Fig Tree Solutions, LLC
> http://www.figtreesolutions.com
> Imports System.Drawing
> Public Function MeasureString(ByVal Value As String, ByVal Font As
> Drawing.Font) As SizeF
> ' Set up string.
> Dim oBitMap As New Bitmap(1, 1)
> Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)
> ' Measure string.
> Dim Size As New SizeF
> Size = oGraphics.MeasureString(Value, Font)
> Return Size
> End Function
> Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
> As Single, ByVal Font As Drawing.Font) As String
> Dim sReturn As String
> If MeasureString(Value, Font).Width < MaxSizeF Then
> sReturn = Value
> Else
> sReturn = Value
> Dim i As Integer
> Do While MeasureString(Value.Substring(0, Value.Length - i) &
> "...", Font).Width > MaxSizeF
> i += 1
> Loop
> sReturn = Value.Substring(0, Value.Length - i) & "..."
> End If
> Return sReturn
> End Function
> ....
> ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS
> THE
> LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
> LONGEST EVER", 300, New Font(New
> System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
Hi Brian,

As for the truncating string values in DataGrid Cell(Table cell), I think
generally we have two means:

1. Truncating the string's length at serverside when we retrieve it from db
or output into the page via code. Just as the other members have suggested.
But this will make the output string's length be a fixed size.

#Creating a Custom DataGridColumn Class, Part 2
http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx

2. Using css style on the output <table> and the text content in table
cell. There is one css attribute named
"OVERFLOW", it can be applied on <div> or <p> ... and when we set the
"OVERFLOW:Hidden", it will truncat the exceeded content according to the
container element's width.

#overflow Attribute | overflow Property
http://msdn.microsoft.com/library/d...uthor/dhtml/ref
erence/properties/overflow.asp

For example:

<p style="OVERFLOW:hidden;WIDTH:100">
<% Response.Write(new String('d',1000)); %>
</p
Also, since in our problem, we need to set the datagrid column's width
unfixed, so we also need to make the with of the <p> as a relative size.
After some testing, it seems that we also have to assign the "table-layout
: fixed" css attribute to the DataGrid(<table>). Here is some demo code on
applying the styles on datagrid:

<asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Column1"
HeaderText="Column1"></asp:BoundColumn>
<asp:BoundColumn DataField="Column2"
HeaderText="Column2"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Column3">
<ItemTemplate>
<p style="OVERFLOW:hidden;WIDTH:90%">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Column3") %>'>
</p>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid
=======================
In our code-behind , we can use the following code (in Page_load) to apply
the "table-layout" style on datagrid:

private void Page_Load(object sender, System.EventArgs e)
{
...............

dgStyle.Style["TABLE-LAYOUT"] = "fixed";
}

Hope these help. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
thanks that worked perfectly!

"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:%23bjDCLxtEHA.3696@.cpmsftngxa10.phx.gbl...
> Hi Brian,
> As for the truncating string values in DataGrid Cell(Table cell), I think
> generally we have two means:
> 1. Truncating the string's length at serverside when we retrieve it from
> db
> or output into the page via code. Just as the other members have
> suggested.
> But this will make the output string's length be a fixed size.
> #Creating a Custom DataGridColumn Class, Part 2
> http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx
> 2. Using css style on the output <table> and the text content in table
> cell. There is one css attribute named
> "OVERFLOW", it can be applied on <div> or <p> ... and when we set the
> "OVERFLOW:Hidden", it will truncat the exceeded content according to the
> container element's width.
> #overflow Attribute | overflow Property
> http://msdn.microsoft.com/library/d...uthor/dhtml/ref
> erence/properties/overflow.asp
> For example:
> <p style="OVERFLOW:hidden;WIDTH:100">
> <% Response.Write(new String('d',1000)); %>
> </p>
> Also, since in our problem, we need to set the datagrid column's width
> unfixed, so we also need to make the with of the <p> as a relative size.
> After some testing, it seems that we also have to assign the "table-layout
> : fixed" css attribute to the DataGrid(<table>). Here is some demo code
> on
> applying the styles on datagrid:
> <asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
> <Columns>
> <asp:BoundColumn DataField="Column1"
> HeaderText="Column1"></asp:BoundColumn>
> <asp:BoundColumn DataField="Column2"
> HeaderText="Column2"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Column3">
> <ItemTemplate>
> <p style="OVERFLOW:hidden;WIDTH:90%">
> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
> "DataItem.Column3") %>'>
> </p>
> </asp:Label>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> =======================
> In our code-behind , we can use the following code (in Page_load) to apply
> the "table-layout" style on datagrid:
> private void Page_Load(object sender, System.EventArgs e)
> {
> ...............
> dgStyle.Style["TABLE-LAYOUT"] = "fixed";
> }
>
> Hope these help. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)

trouble binding a datagrid to a custom collection

I'm trying to bind a custom collection to an autogenerated datagrid without
success.
I'm getting this error:
DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks
.
Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form>
//----
Code behind:(NewsContent.aspx.cs).
public class NewsContent{
private void Page_Load(object sender, System.EventArgs e)
{
ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}
private ListItemCollection AddToCustomCollection()
{
ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);
return myListCollection;
}
//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}
//----
--
I'm using a collection class: (ListItemCollection.cs):
public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}
public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}
public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}
}Try setting the autogeneratecolumn property for this datagrid to True.
"viktor9990" wrote:

> I'm trying to bind a custom collection to an autogenerated datagrid withou
t
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Than
ks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //----
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2"
,
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //---
--
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }

trouble binding a datagrid to a custom collection

I'm trying to bind a custom collection to an autogenerated datagrid without
success.
I'm getting this error:

DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks.

Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form
//---------------------

Code behind:(NewsContent.aspx.cs).
public class NewsContent{

private void Page_Load(object sender, System.EventArgs e)
{

ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}

private ListItemCollection AddToCustomCollection()
{

ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);

return myListCollection;
}

//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}

//------------------------

I'm using a collection class: (ListItemCollection.cs):

public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}

public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}

public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}

}Try setting the autogeneratecolumn property for this datagrid to True.

"viktor9990" wrote:

> I'm trying to bind a custom collection to an autogenerated datagrid without
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Thanks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //---------------------
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //------------------------
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }

Monday, March 26, 2012

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:

*PSEUDOCODE*

for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE

It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.

Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.

Specifically, what I try to do is store the TextBoxes for comparison
in an array:

Dim ControlName As String' temporary

ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)

' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
...

(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.

Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.

I just thought of a less repetitive algorithm.

Provided I can dynamically obtain the index of the current row:

*PSEUDOCODE*

for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE

Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.

> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE

...

> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
>Dim aObjFirst(2) As TextBox
> Dim ControlName As String' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.

I have a DataGrid containing a TextBox control and a CustomValidator in
each row.

The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.

The algorithm is pretty straightforward:

*PSEUDOCODE*

senderIndex = the row in the DataGrid of the sender

FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE

However, I'm stuck in my attempts to formally code this algorithm:

*CODE*

Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False

For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToV alidate)

If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub

I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.

(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._

--E.)

Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum

'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender

'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent

'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent

'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward:
*PSEUDOCODE*
for i=1 thru ( Container.Length-1 )
for j=i+1 thru ( Container.Length-1 )
if ( TextBox[i]==TextBox[j] )
TRUE
It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.
Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/d...bformspages.asp)
but the concept still baffles me.
Specifically, what I try to do is store the TextBoxes for comparison
in an array:
Dim ControlName As String ' temporary
ControlName = OurDataGrid.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)
' If first names match...
If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
..
(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.
Can anyone follow where I'm going with this and provide some
insightful direction?--or a totally different approach would be welcome. Anything that
could help, really.
I just thought of a less repetitive algorithm.
Provided I can dynamically obtain the index of the current row:
*PSEUDOCODE*
for i=currentIndex thru ( DataGrid.Controls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE
Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.

> I have a DataGrid containing a TextBox control and a CustomValidator
> in each row. The CustomValidator fires a function that compares all
> TextBoxes for equality. The algorithm for comparison is
> straightforward:
> *PSEUDOCODE*
> for i=1 thru ( Container.Length-1 )
> for j=i+1 thru ( Container.Length-1 )
> if ( TextBox[i]==TextBox[j] )
> TRUE
>
...

> Specifically, what I try to do is store the TextBoxes for comparison
> in an array:
> Dim aObjFirst(2) As TextBox
> Dim ControlName As String ' temporary
> ControlName = OurDataGrid.Controls(i).UniqueID
> aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ControlName = OurDataGrid.Controls(j).UniqueID
> aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)
> ' If first names match...
> If ( aObjFirst(0).Text=aObjFirst(1).Text ) Then
> ...
> (Yes, I'm comparing first names.) However, this always warns me that
> j is out of range. And getting back to the msdn, it seems to be
> discouraging the technique of name concatenation I used to get at the
> controls I want.
> Can anyone follow where I'm going with this and provide some
> insightful direction?
Same question, different day, (hopefully) worded more clearly.
I have a DataGrid containing a TextBox control and a CustomValidator in
each row.
The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.
The algorithm is pretty straightforward:
*PSEUDOCODE*
senderIndex = the row in the DataGrid of the sender
FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE
However, I'm stuck in my attempts to formally code this algorithm:
*CODE*
Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False
For ( i = SENDER_INDEX+1 ) To ( DataGrid.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToValidate)
If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_INDEX"--I can't figure out how
to reveal the row number of the sender. This is my question.
(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)
(Here's an answer I received from another post, that _works._
--E.)
Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidators in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIndex)

Saturday, March 24, 2012

trouble with click triggered events

i have a datagrid with delete text links.

I want a confirmation to be made after clicking delete once.


protected void DataGrid1_Del(object sender, DataGridCommandEventArgs e)
{
// make sure things that are invisible stay that way. Also make sure all fields are still blank.
ClearForm();
DataGrid1.EditItemIndex= -1;

MsgLabel.Text = "Are you sure you want to delete the record?";
MsgLabel.Visible = true;
CancelBtn.Visible = true;
DeleteBtn.Visible = true;

} // end DataGrid1_Del

private void DeleteBtn_Click(object sender, System.EventArgs e)
{
String deleteCmd = "DELETE from Inventory where InvName = @dotnet.itags.org.InvName";

SqlCommand myCommand = new SqlCommand(deleteCmd, sqlConnection1);
myCommand.Parameters.Add(new SqlParameter("@dotnet.itags.org.InvName", SqlDbType.NVarChar, 20));
myCommand.Parameters["@dotnet.itags.org.InvName"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];****

myCommand.Connection.Open();
myCommand.ExecuteNonQuery();

myCommand.Connection.Close();
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);

DataGrid1.DataBind();
}

What this code is SUPPOSED to do is, when the delete event is triggered, it will ask you if you are sure you want to delete the record. Upon clicking either delete or cancel, you will call the corresponding function.

The problem here is that, in my DeleteBtn_Click function, it does not recognize e.Item.ItemIndex, b/c this function e is System.EventArgs, instead of DataGridCommandEventArgs. (line is marked ****)

Does anyone have any suggestions to accomplish what I'm trying to do here?

Thanks,
TomIf I understand correctly, in "DataGrid1_Del()" can you save the "itemindex" in a session object and further use it in "DeleteBtn_Click()"?
Hope this helps
Yugang

_______________________

This posting is provided "AS IS" with no warranties, and confers no rights.
could you direct me to info on sessions? That is outside my "knowledge base." :D
Inside "DataGrid1_Del()" use code to record itemindex:
Session.Add("ItemIndex", e.Item.ItemIndex)

Inside "DeleteBtn_Click" get value from session:
Dim itenIndex As Integer = CInt(Session.Item("ItemIndex"))

For complete introduction, please refer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsessionstate.asp

Hope this helps
Yugang
I will check the link you provided, thanks.

Initially, when I modify my code as you suggested, in the:

int itemIndex = CInt(Session.Item("ItemIndex"))

line, Session does not have a definition for "Item." (C#)

Are you sure this is correct? Like I said, I'll be checking that link.
Sorry to provide you with VB Code. For C# the code should be:
int itemIndex = int.Parse(Session["ItemIndex"].ToString())
Thanks
Yugang
cool deal, so what should I use in this line?

myCommand.Parameters["@.InvName"].Value = DataGrid1.DataKeys[(int)e.Item.ItemIndex];

What would I replace e.Item.ItemIndex with?

thanks Yugang!
ooops, as i clicked post, i saw what i was looking at, stupid me. I put

myCommand.Parameters["@.InvName"].Value = DataGrid1.DataKeys[itemIndex];

right?
Yes. Please try it
Thanks
Yugang
worked like a charm, much thanks Yugang!!!

Tom
I would stay away from the Session object (this also goes with Application) object. They have many problems (like thread affinity) which cause scaling problems.