如何使用button to serverclick从gridview中的行获取值?
这是我的代码:
<dx:ASPxGridView ID="gvwListApprover" runat="server" Width="460px">
<Columns>
<dx:GridViewDataTextColumn Caption="No" FieldName="Sequential" Width="20px"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="KodePosition" FieldName="KodePosition" Width="175px"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Jabatan" FieldName="NamaPosition" Width="175px"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn Caption="Nama" FieldName="UserLogin" Width="265px"></dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn ReadOnly="True" Caption="Action">
<DataItemTemplate>
<input type="button" id="btnDelApp" onserverclick="btnDelApp_ServerClick('<%#Eval("KodePosition")%>');" value="Delete" runat="server" class="lookupstyle" />
</DataItemTemplate>
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
来自onserverclick,我希望得到代码隐藏的价值。
protected void btnDelApp_ServerClick(object sender, EventArgs e)
{
//how to get value from row in gridview event button on serverclick ?
}
请纠正并给我解决方案。 感谢
答案 0 :(得分:0)
U可以使用点击的RowDataBoundEvent。 不要为控件添加任何explict事件。 GridView自动检测在其中单击的控件的事件。
protected void grdClickDoubleClick_RowDataBound(object sender, GridViewRowEventArgs e) //formatted the c# code
{
GridViewRow row = e.Row;
if (row.RowType == DataControlRowType.DataRow)
{
//*******************************************************8
// code here. (This code given below)
//
}
}
单击事件分配
LinkButton _singleClickButton = row.FindControl("lnkBtnClk") asLinkButton;
string _jsSingleClick = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "");
e.Row.Attributes.Add("onclick", _jsSingleClick);
用于双击事件分配
LinkButton _dblClickButton = row.FindControl("lnkBtnDblClk") asLinkButton;
string _jsDoubleClick = ClientScript.GetPostBackClientHyperlink(_dblClickButton, "");
e.Row.Attributes.Add("ondblclick", _jsDoubleClick);
我们可以在行命令方法中处理这个已分配的事件,如下所示。
protected void grdClickDoubleClick_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
switch (e.CommandName)
{
case"clk": //"clk" is command name of linkButton Row click event handler
grdClickDoubleClick.SelectedIndex = row.RowIndex;
break;
case"dblClk"://"dblClk" is command name of linkButton Row Double click event handler.
row.BackColor = System.Drawing.Color.Pink;
break;
}
}
如果我们要同时处理点击和双击,那么我们必须稍微更改上面的点击处理程序
LinkButton _singleClickButton = row.FindControl("lnkBtnClk") asLinkButton;
string _jsSingleClick = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "");
///We make the script as below format.
//javascript:setTimeout("POSTBACK SCRIPT", 500)
_jsSingleClick = _jsSingleClick.Insert(11, "setTimeout(\"");
_jsSingleClick += "\", 500)";
e.Row.Attributes.Add("onclick", _jsSingleClick);
然后我们可以处理行单击和双击。