简体   繁体   English

如何使用asp.net中的Javascript在ButtonClick上获取GridView行值?

[英]How to Get GridView Row Values on ButtonClick using Javascript in asp.net?

I have a GridView in my asp.net Applicaiton. 我的asp.net应用程序中有一个GridView i have a Button with javascript function which shows the values of selected row in Div . 我有一个带有javascript函数的Button ,它显示Divselected行的值。 How to get all Grid Column values of Selected Row on ButtonClick . 如何Column values of Selected Row on ButtonClick所有“ Grid Column values of Selected Row on ButtonClick

在此处输入图片说明 Javascript: Javascript:

function SetRowValues(id, controlid, fair, good, mint, nnew, poor,broken) {
            //alert(id + " " + fair + " " + controlid);
            $("#divSelectedRow").html("TPCCID: " + id + " Fair:" + fair + " Good: " + good + " Mint: " + mint + " New: " + nnew + " Poor: " + poor + " Broken: " + broken);
            $("#divSelectedRow").css("display", "block");
            return false;
    }

Grid Markup: 网格标记:

<asp:TemplateField HeaderText="Source" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center"
    HeaderStyle-HorizontalAlign="Center">
    <ItemTemplate>
 <asp:Button ID="BtnSource" runat="server" CausesValidation="false" OnClick='<%# "return SetRowValues("+Eval("ttppcid")+",this.id,"+Eval("Fair")+","+Eval("Good")+","+Eval("Mint")+","+Eval("Poor")+","+Eval("Broken")+")"%>' Text="Source" />
  </ItemTemplate>
</asp:TemplateField>

Here, i want to get all the column values of selected row using Javascript . 在这里,我想使用Javascript获取selected row所有列值。 Note : When the Value for column1 is string containing Space eg: "Cell Phone" then the script wont work. 注意 :如果column1的值是包含空格的字符串,例如:“手机”,则脚本将无法工作。 Please help me to get the entire row values using javascript on Button Click . 请帮助我在Button Click上使用javascript获取整个row值。

Help Appreciated! 帮助赞赏!

I think you have make mistake in preparing the Javascript function call. 我认为您在准备Javascript函数调用时犯了错误。

Missing single quote around parameters '' . 参数''周围缺少单引号。

<asp:TemplateField HeaderText="Source" ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center"
    HeaderStyle-HorizontalAlign="Center">
    <ItemTemplate>
 <asp:Button ID="BtnSource" runat="server" CausesValidation="false" 
OnClick='<%# "return SetRowValues('"+Eval("ttppcid")+"',this.id,'"+Eval("Fair")+"','"+Eval("Good")+"','"+Eval("Mint")+"','"+Eval("Poor")+"','"+Eval("Broken")+"')"%>' Text="Source" />
  </ItemTemplate>
</asp:TemplateField>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM