当前位置: 动力学知识库 > 问答 > 编程问答 >

gridview - Accessing the value of a passed in argument to click event c#

问题描述:

I have a gridview defined like this...

<asp:GridView runat="server" id="gvProjectLineage"

ShowFooter="false"

DataKeyNames="projectLineageID"

AutoGenerateColumns="False"

AllowPaging="false"

AllowSorting="false"

RowStyle-CssClass="shade" CellSpacing="1"

AlternatingRowStyle-CssClass="unshade"

BorderColor="Transparent"

DataSourceID="gvProjectLineageDataSource"

Width="100%">

<HeaderStyle HorizontalAlign="Left" Font-Underline="true"></HeaderStyle>

<Columns>

<asp:BoundField ReadOnly="True"

HeaderText="Lineage ID"

InsertVisible="false"

DataField="projectLineageID"

HeaderStyle-CssClass="columnHeader"

ItemStyle-VerticalAlign="Top"

Visible="false">

</asp:BoundField>

<asp:BoundField ReadOnly="True"

HeaderText="Relationship type"

InsertVisible="false"

DataField="projectRelationshipType"

HeaderStyle-CssClass="columnHeader"

ItemStyle-VerticalAlign="Top"

Visible="true">

</asp:BoundField>

<asp:BoundField ReadOnly="True"

HeaderText="Related Project"

InsertVisible="false"

DataField="projectTitle"

HeaderStyle-CssClass="columnHeader"

ItemStyle-VerticalAlign="Top"

Visible="true">

</asp:BoundField>

<asp:TemplateField ShowHeader="False"

HeaderStyle-Font-Underline="false"

ItemStyle-HorizontalAlign="Left"

FooterStyle-HorizontalAlign="Left">

<ItemTemplate>

<asp:LinkButton ID="btnDelete"

CommandArgument='<%# Eval("projectLineageID") %>'

CommandName="Delete"

runat="server">

<img style="border:none;"

src="/content/images/icon/deleteIcon.png"

title="Delete this lineage" />

</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField ShowHeader="False"

HeaderStyle-Font-Underline="false"

ItemStyle-HorizontalAlign="Left"

FooterStyle-HorizontalAlign="Left">

<ItemTemplate>

<asp:LinkButton ID="btnDeleteAll"

CommandArgument='<%# Eval("projectLineageID") %>'

runat="server"

OnClick="btnDeleteAll_Click" >

<img style="border:none;"

src="/content/images/icon/deleteIcon.png"

title="Delete this lineage AND it's reciprocal lineage" />

</asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<EmptyDataTemplate>There are currently no relationships identified for this S&T project.</EmptyDataTemplate>

</asp:GridView>

The first "delete" button calls a simple delete query and it works fine to delete the selected row from the table. However, when I call the 2nd delete button ("DeleteAll"), I want to use the [projectLineageID] to find the related lineage records for a project and delete them all at once.

When I call the 2nd delete function "onclick" as follows, I get nothing in column [0].

protected void btnDeleteAll_Click(object sender, EventArgs e)

{

//Delete lineage and reciprocal lineage for relationship types 1 (Transitioned from) and 2 (Transitioned to)

util u = new util();

GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;

string strRelID = grdrow.Cells[0].Text;

int intRelID = System.Convert.ToInt32(grdrow.Cells[0].Text);

string relType = grdrow.Cells[1].Text;

string relProj = grdrow.Cells[2].Text;

Response.Write ("Deleting relationship between " + projectID + " and the project in column 3 " + relID + " " + relType + " " + relProj + " :");

}

How do I get the projectLineageID to pass it to the query?

And, why can't I display it? Even if I try to "convert" it, I get an error telling me the "Input string was not in a correct format."

Thanks,

Bob

分享给朋友:
您可能感兴趣的文章:
随机阅读: