how to put two column in a commandargument? CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Docid") %>'

Hi guys,

I need help once again. I just want to ask how can i put two columns in  my CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Docid") %>'

I wanna put two columns inside the commandargument which i'll be using for the deleting. The columns will be use as a filter in deleting.

 

Here's the code of my gridview: 

 

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        BackColor="#FFE0C0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
                        ForeColor="#000066" GridLines="Horizontal" TabIndex="1" Width="950px" OnRowCommand="GridView1_RowCommand"
                        OnPageIndexChanging="GridView1_PageIndexChanging">
                        <PagerSettings FirstPageImageUrl="~/images/ll_arrows.gif" FirstPageText="" LastPageImageUrl="~/images/rr_arrrow.gif"
                            LastPageText="" Mode="NextPreviousFirstLast" NextPageImageUrl="~/images/r_arrow.gif"
                            NextPageText="" PreviousPageImageUrl="~/images/l_arrow.gif" PreviousPageText="" />
                        <FooterStyle Height="25px" />
                        <RowStyle BackColor="White" Height="20px" />
                        <Columns>
                            <asp:BoundField DataField="PageName" HeaderText="Page Name">
                                <HeaderStyle BackColor="Silver" Font-Bold="True" Font-Size="14px" ForeColor="White" />
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="URL">
                                <ItemTemplate>
                                    <a id="livelink" href='http://<%# Eval("URL") %>' target="_blank">
                                        <%# Eval("URL")%>
                                    </a>
                                </ItemTemplate>
                                <HeaderStyle BackColor="Silver" Font-Bold="True" Font-Size="14px" ForeColor="White" />
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False">
                                <ItemTemplate>
                                    <asp:Button ID="Button2" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Docid") %>'
                                        CssClass="button" CommandName="btnErase" Text="Delete Link" CausesValidation="false" />
                                </ItemTemplate>
                                <HeaderStyle BackColor="Silver" />
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle BackColor="Silver" Height="25px" />
                        <HeaderStyle Height="25px" />
                        <AlternatingRowStyle BackColor="GhostWhite" Height="20px" />
                    </asp:GridView>

 

 

 


Thanks,

*A newbie C# programmer*
0
nhoyti
2/21/2008 8:24:14 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
649 Views

Similar Articles

[PageSpeed] 57

This is not the right way of deleting. Try changing the following lines to accomplish your goal:

1. First, change the button to as follows:
    <asp:Button ID="Button2" runat="server" CssClass="button" CommandName="Delete" Text="Delete Link" CausesValidation="false" />

2. Now in your Grid, Add a new event

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        BackColor="#FFE0C0" BorderColor="Gray" BorderStyle="Solid" BorderWidth="1px"
                        ForeColor="#000066" GridLines="Horizontal" TabIndex="1" Width="950px" OnRowCommand="GridView1_RowCommand"
                        OnPageIndexChanging="GridView1_PageIndexChanging"  OnRowDeleting="GridView1_RowDeleting">

 

3. Now add a new templatefield in your grid (or if you are already showing those columns, show them in Label / Hyperlink or any web control:

<Columns>
                            <asp:BoundField DataField="PageName" HeaderText="Page Name">
                                <HeaderStyle BackColor="Silver" Font-Bold="True" Font-Size="14px" ForeColor="White" />
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="URL">
                                <ItemTemplate>
                                    <a id="livelink" href='http://<%# Eval("URL") %>' target="_blank">
                                        <%# Eval("URL")%>
                                    </a>
                                </ItemTemplate>
                                <HeaderStyle BackColor="Silver" Font-Bold="True" Font-Size="14px" ForeColor="White" />
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False">
                                <ItemTemplate>
                                    <asp:Button ID="Button2" runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Docid") %>'
                                        CssClass="button" CommandName="btnErase" Text="Delete Link" CausesValidation="false" />
                                </ItemTemplate>
                                <HeaderStyle BackColor="Silver" />
                            </asp:TemplateField>
                            <asp:TemplateField Visible="false">
                                 
<ItemTemplate>
                                          
<asp:Label ID="lblCol1Value" runat="Server" Text='<%# Eval(Col1) %>' />
                                          
<asp:Label ID="lblCol2Value" runat="Server" Text='<%# Eval(Col2) %>' /> 
                                 
</ItemTemplate> 
                           
</asp:TemplateField>
</Columns>

4. Now add event's code in your code:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
   GridViewRow row = GridView1.Rows[e.RowIndex];
   string value1 = ((Label)row.FindControl("lblCol1Value")).Text;
   string value2 = ((Label)row.FindControl("lblCol2Value")).Text;
   // Call Your Delete Function Code and use Value 1, Value 2, or even all the values you want.

}

It's done.


Talha
MCP, MCAD
Personal Site
0
talha83
2/21/2008 10:03:41 AM

Concatenate the two values using a delimiter.

                            asp:TemplateField ShowHeader="False">
                                <ItemTemplate>
                                    <asp:Button ID="Button2" runat="server" CommandArgument='<%# Eval("Docid") + "-" + Eval("AnotherField") %>'
                                        CssClass="button" CommandName="btnErase" Text="Delete Link" CausesValidation="false" />
                                </ItemTemplate>
                                <HeaderStyle BackColor="Silver" />
                            </asp:TemplateField>

 Thanks

-Mark post(s) as "Answer" that helped you 


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
2/21/2008 10:31:02 AM

Hi guys,

 

Thank you for all the help.

 

 

Graciaz,

Nhoyti 


Thanks,

*A newbie C# programmer*
0
nhoyti
2/21/2008 11:02:32 AM
Reply:

Similar Artilces:

Template field and href?? <a href='<%# DataBinder.Eval(Container.DataItem,"urunnumarasi",Request.ApplicationPath+"/detayliurun.aspx?urunnumarasi={0}") %>'> ....how can i send categor, category1 with u
hi friends my code is below.. how can i send categor, category1 with urunnumarasi with below code?  catagory and category1 are other coulumname <a href='<%# DataBinder.Eval(Container.DataItem,"urunnumarasi",Request.ApplicationPath+"/detayliurun.aspx?urunnumarasi={0}") %>'> cheersMark as me if my question or my answer can be helpful for you :) Hi oguzkaygun, Try this: <a href='<%# Request.ApplicationPath+"/detayliurun.aspx?" + DataBinder.Eval(Container.DataItem, "category") + "=" + DataBinder.Ev...

I am trying to dynamically change the binding code of controls in a listview with codebehind. How do I present a double quote as in the following '<%# Eval("ArtificialID") %>'
I am tyring to set the text property as in the following. label1.text = "'<%# Eval("ArtificialID") %>'" I have a problem were double quotes exist such as "ArtificalID".  It thinks that I am done with the string when I am not.  I have forgotten how to do this. It doesnt work to use a singel quote instead.  Any help woudl be very much appreicated. Thanks  I am not quite sure what you are trying to do but you can try this "'<%# Eval(\"ArtificialID\") %>'";   take note of t...

how can i use coulumname instead of "/detayliurun.aspx?urunnumarasi={0}" in <a href='<%# DataBinder.Eval(Container.DataItem,"urunnumarasi",Request.ApplicationPath+"/detayliurun.aspx?urunnumarasi={0}"
hello friends how can i use coulumname instead of "/detayliurun.aspx?urunnumarasi={0}" in below code.. because i want to send different page.aspx:) i insterted different page.aspx in coulumanem before..  <a href='<%# DataBinder.Eval(Container.DataItem,"urunnumarasi",Request.ApplicationPath+"/detayliurun.aspx?urunnumarasi={0}") %>'> cheersMark as me if my question or my answer can be helpful for you :) Hi friend, I think you can assign "detayliurun.aspx?urunnumarasi=1" to the coulumname(table field) to ...

Web Custom Control for <%# DataBinder.Eval(Container.DataItem, "column") %>
Dear Gurrest of the Guru's: I need to write a Web Custom Control to use in replace of <%# DataBinder.Eval(Container.DataItem, "column") %>. Although I'm somewhat new to .Net, I have successfully developed several simple Web Custom Controls, but this one has me stumped. Here is my current pathetic attempt at writing this Control: Imports System.ComponentModel Imports System.Web.UI Imports System.Web.UI.UserControl <DefaultProperty("Text"), ToolboxData("<{0}:pullData runat=server></{0}:pullData>")> Public Class pullDat...

Why Response.Write("<script>window.open("newWind.aspx','report','');</script>") not working?
I need to open a new web browser of url=newWind.aspx and tried the code below; Response.Write("<script>window.open('newWind.aspx','report','');</script>")However nothing happens, what can I do to make it work? Try RegisterClientScriptBlock("OpenWin","<script language=javascript>window.open('newWind.aspx','report','');</script>")I think that is the name of it...Also look at RegisterStartupScriptBlock (I think)MajorCats Thanks. But, it was same difference. Is there anything that blocks the new browser from showing up in the setting of IE or system?   &nbs...

How to put Response.Write("<script language='javascript' type='text/javascript'>") into custom server control
Hello, In my Page_Load I have the following code: =====  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Response.Write("<script language='javascript' type='text/javascript'>" & vbCrLf) Response.Write("Function();") Response.Write("</script>") End Sub =====  Because I want to re-use this on every webpage, I want to build a custom server control. How can I implement this?Johan TheunissenMCPD, MCSE, MCTS BizTalk 2006==============================Please mark the most helpful reply/replies as "Answer". ...

Manipulating <%# DataBinder.Eval(Container.DataItem,"Field") %>'s inside a repeater
Hi all - can anyone tell me how I change/work with the contents of asp:repeater's - i'd like to split one by the comma character into an array, and show the first item in the array. An example in C# would be really good. Thanks for any help!Ramic Solutions Try something like this:<%# GetFirstItem(DataBinder.Eval(Container.DataItem,"Field") )%>And in Code-behind:public string GetFirstItem(object value){   string[] items = ((string)value).Split(',');   if (items.Lenght > 0)      return items[0];   ...

Give access to non virtual folder through configuration entry? ERROR: <location> path attribute must be a relative virtual path. It cannot contain any of '?' ':' '\' '*' '"' '<' '>' or '|'.
I have a webpage running under a virtual directory that is mapped to d:/webapplication that produces an excel spreadsheet, the page calls a library object that generates a report and places it in a folder d:/attachments. This folder is not in the virtual directory. When I access the webpage i click a button and it attemps to return the created spreadsheet as a mim content type application/vnd.ms-excel. However i getting redirected back to the login page of the application. Ive also noticed that the excel spreadsheet has not even been created at this location. So assuming this...

help with: BackColor='<%#iif((eval("timecode") = 1),"#993366","#993366") %>'
I have a panel and I wish to toggle its background color based on a databound value.  the expression returns all OK. Butit reutrns a string and it creates a casting error it returns "#993366" BackColor='<%#iif((eval("timecode") = 1),"#993366","#993366") %>' I know it is the declaration... something to do with the # in the <%# or ???   Hi That's the problem when you type it in there directly. It's a pain in the ass to debug/manage.Maybe you can take a look at this example. You add a function in your code-be...

I'm getting an error using NavigateURL ='<%# Eval("Url") %>', it works when using NavigateURL="intro.aspx"
I'm getting an error using NavigateURL ='<%# Eval("Url") %>', it works when I use NavigateURL="intro.aspx" Server Error in '/orthoassist' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. Requested URL: /orthoassist/intro.aspx <asp:HyperLink runat="server" ID="hl1" Text=...

what does this mean DataBinder.Eval(Container.DataItem,"cityname")??DataBinder.Eval(Container.DataItem,"cityname")
Hi, Can somebody pls tell me wat does the following line mean and wat does it return ?? DataBinder.Eval(Container.DataItem,"cityname") I guess this means that return the datagrid item value in column named "cityname". Plss calrify, in details if possible. Thanks!!!! Hi, Take a look @ DataBinder.Eval HTH K B ShajudeenAreYaar.comDubai, United Arab Emirates. Hi, well what I read is that databinder.Eval convert the returning type to string and its basically used in control that are containers which are datagrid, datalist and repe...

<img src='<%=PathPrefix + "Comm/Images/sp.gif" %>' height="8" width="20">- What is PathPrefix
<img src='<%=PathPrefix + "Comm/Images/sp.gif" %>' height="8" width="20"> What is PathPrefix ?-----------------------------------------------Please click Mark as Answer if this helped. PathPrefix is a public shared variable in the code behind file of this pageDo mark as answer if it helpsBest RegardsAli Sufyan ButtSoftware EngineerElectronic Solutions Pvt. Limited...

<%# DataBinder.Eval(Container.DataItem, "Test", "{0:C}") %>
I use this code <%# DataBinder.Eval(Container.DataItem, "Test", "{0:C}") %> to display a number from the Database with only two decimals. But I get his result € 130,30 but I want only 130,30. What can I do?? You are asking the number to be formatted as currency so that is what you get. Format it as a number rather than C for Currency.Mike Schellenberger - MCAD...

<script language='JavaScript'>location.href="#control"</script>
I tried to use asp to register this block of script into the page to direct the page to the control that the user was working on before postback, it works fine on IE, however, when I try it on netscape, the page is not showing but when I do view source, all the code are there. Anybody knows what happened and how to fix it? Thanks in advance. My guess would be that Netscape just happens to be pickier about the url starting with a hash. Try using the entire url plus the hash and see if Netscape behaves better. > Try using the entire url plus the hash Hmmm ... that might actua...

Web resources about - how to put two column in a commandargument? CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Docid") %>' - asp.net.presentation-controls

Resources last updated: 1/7/2016 10:06:40 AM