e.command="Select"

  • Thread starter Thread starter ypul
  • Start date Start date
Y

ypul

I have a datagrid
now in my Datagrid I have select column(0),
with text field as ID, so that user can click on Id.
now when the user clicks on Id I want the Id text

private Sub dg_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand

If e.CommandName = "Select" Then

e.Item.Cells(0).Text 'I want this value which is actually the select column

'above line give me blank ,"".

End If

How should I get the value of select column ?
 
Customermaster.aspx
---------
<asp:datagrid id="dg" runat="server" Width="100%" Height="0px" BorderStyle="Solid" GridLines="Vertical" CellPadding="3" BackColor="White" BorderWidth="1px" BorderColor="White" AllowSorting="True" AutoGenerateColumns="False" PageSize="15">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<EditItemStyle CssClass="RowWhite"></EditItemStyle>
<AlternatingItemStyle Width="800px" CssClass="RowPaleBlue"></AlternatingItemStyle>
<ItemStyle CssClass="RowWhite"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True" CssClass="HeaderRow"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>




<asp:ButtonColumn DataTextField="CustomerCode" SortExpression="CustomerCode" HeaderText="Customer Code" CommandName="Select"></asp:ButtonColumn>




<asp:BoundColumn DataField="CustomerName" HeaderText="Customer Name"></asp:BoundColumn>
<asp:BoundColumn DataField="StartDate" SortExpression="StartDate" HeaderText="Start Date" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundColumn>
<asp:BoundColumn DataField="EndDate" SortExpression="EndDate" HeaderText="End Date" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" Position="Top" CssClass="Pager" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

-------------------------------------
Customermaster.aspx.vb
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand
If e.CommandName = "Select" Then

Response.Redirect("CustomerDetail.aspx?CampaignId=" & e.Item.Cells(0).Text)

End If

End Sub

------------------

I get the values for other columns but not for select column using "e.Item.Cells(0).Text"
 
hmm, not sure why you can't get it from the button column - you may need to cast it or something.
As a test, try create a BoundColumn before the Button column that contains the value your trying to Retrieve.
You can set the visibility to false if you don't want it to be seen,
then e.Item.Cells(0).Text should work

so:

<Columns>
<asp:BoundColumn DataField="CustomerCode" ></asp:BoundColumn> <!-- leave as visible to start off with so you can see the data is actually there -->
<asp:ButtonColumn DataTextField="CustomerCode" SortExpression="CustomerCode" HeaderText="Customer Code" CommandName="Select"></asp:ButtonColumn>
...
</Columns>

HTH
Customermaster.aspx
---------
<asp:datagrid id="dg" runat="server" Width="100%" Height="0px" BorderStyle="Solid" GridLines="Vertical" CellPadding="3" BackColor="White" BorderWidth="1px" BorderColor="White" AllowSorting="True" AutoGenerateColumns="False" PageSize="15">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<EditItemStyle CssClass="RowWhite"></EditItemStyle>
<AlternatingItemStyle Width="800px" CssClass="RowPaleBlue"></AlternatingItemStyle>
<ItemStyle CssClass="RowWhite"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True" CssClass="HeaderRow"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>




<asp:ButtonColumn DataTextField="CustomerCode" SortExpression="CustomerCode" HeaderText="Customer Code" CommandName="Select"></asp:ButtonColumn>




<asp:BoundColumn DataField="CustomerName" HeaderText="Customer Name"></asp:BoundColumn>
<asp:BoundColumn DataField="StartDate" SortExpression="StartDate" HeaderText="Start Date" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundColumn>
<asp:BoundColumn DataField="EndDate" SortExpression="EndDate" HeaderText="End Date" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" Position="Top" CssClass="Pager" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

-------------------------------------
Customermaster.aspx.vb
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand
If e.CommandName = "Select" Then

Response.Redirect("CustomerDetail.aspx?CampaignId=" & e.Item.Cells(0).Text)

End If

End Sub

------------------

I get the values for other columns but not for select column using "e.Item.Cells(0).Text"
 
yep, I have already done with a invisible column and fetched the value, but I was wondering about the
<asp:ButtonColumn DataTextField

any way ..thanks for the efforts..Grant

Cheers ,
Vipul
hmm, not sure why you can't get it from the button column - you may need to cast it or something.
As a test, try create a BoundColumn before the Button column that contains the value your trying to Retrieve.
You can set the visibility to false if you don't want it to be seen,
then e.Item.Cells(0).Text should work

so:

<Columns>
<asp:BoundColumn DataField="CustomerCode" ></asp:BoundColumn> <!-- leave as visible to start off with so you can see the data is actually there -->
<asp:ButtonColumn DataTextField="CustomerCode" SortExpression="CustomerCode" HeaderText="Customer Code" CommandName="Select"></asp:ButtonColumn>
...
</Columns>

HTH
Customermaster.aspx
---------
<asp:datagrid id="dg" runat="server" Width="100%" Height="0px" BorderStyle="Solid" GridLines="Vertical" CellPadding="3" BackColor="White" BorderWidth="1px" BorderColor="White" AllowSorting="True" AutoGenerateColumns="False" PageSize="15">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<EditItemStyle CssClass="RowWhite"></EditItemStyle>
<AlternatingItemStyle Width="800px" CssClass="RowPaleBlue"></AlternatingItemStyle>
<ItemStyle CssClass="RowWhite"></ItemStyle>
<HeaderStyle Font-Size="Smaller" Font-Names="Arial" Font-Bold="True" CssClass="HeaderRow"></HeaderStyle>
<FooterStyle BackColor="#CCCCCC"></FooterStyle>
<Columns>




<asp:ButtonColumn DataTextField="CustomerCode" SortExpression="CustomerCode" HeaderText="Customer Code" CommandName="Select"></asp:ButtonColumn>




<asp:BoundColumn DataField="CustomerName" HeaderText="Customer Name"></asp:BoundColumn>
<asp:BoundColumn DataField="StartDate" SortExpression="StartDate" HeaderText="Start Date" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundColumn>
<asp:BoundColumn DataField="EndDate" SortExpression="EndDate" HeaderText="End Date" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" Position="Top" CssClass="Pager" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

-------------------------------------
Customermaster.aspx.vb
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.ItemCommand
If e.CommandName = "Select" Then

Response.Redirect("CustomerDetail.aspx?CampaignId=" & e.Item.Cells(0).Text)

End If

End Sub

------------------

I get the values for other columns but not for select column using "e.Item.Cells(0).Text"
 
Back
Top