Mohd Aamir

Mohd Aamir

  • NA
  • 68
  • 4.5k

Active button should be changed into inactive button on clik

Oct 17 2018 6:21 AM
Hell Guyzz..!
i m here again to take your support hope u will solve it as soon as possible and i will be your thankfull
 
 on click active button it should be changed into inactive in while click on in active it should be changed again into active 
 
here you go my gridview design and code:
 
Back
IDCetagoryNameColorPriceClick_itClick_ItClick_ItStatus
43 0 toshiba kala 221 Delet Edit update Active Inactive
45 0 mui9 yelloww1 190001 Delet Edit update Active Inactive
47 1 samsung black 32000 Delet Edit update Active Inactive
49 1 blackberry totally black 72000 Delet Edit update Active Inactive
50 1 wwwww wwwww 2222222 Delet Edit update Active Inactive
52 2 samsung black 2000 Delet Edit update Active Inactive
53 3 hp black 32000 Delet Edit update Active Inactive
69 1 samsung white 300000 Delet Edit update Active Inactive
93 1 Dsk Black 78888 Delet Edit update Active Inactive
94 1 i3computer Blue 16000 Delet Edit update Active Inactive
95 1 hp Blue 16000 Delet Edit update Active Inactive
96 2 samsung black 16000 Delet Edit update Active Inactive
97 2 hp white 22000 Delet Edit update Active Inactive
98 1 samsung Blue 16000 Delet Edit update Active Inactive
99 1 samsung Blue 16000 Delet Edit update Active Inactive
100 1 samsung black 16000 Delet Edit update Active Inactive
105 1 hp black 12000 Delet Edit update Active Inactive
106 3 samsung black 16000 Delet Edit update Active Inactive
107 1 mi9 white 32000 Delet Edit update Active Inactive
108 3 mi99 mehroom 20000 Delet Edit update Active Inactive
109 3 i3computer white 16000 Delet Edit update Active Inactive
110 1 samsung black 32000 Delet Edit update Active Inactive
111 1 samsung Blue 12000 Delet Edit update Active Inactive
112 2 i3computer black 32000 Delet Edit update Active Inactive
114 2 samsung black 16000 Delet Edit update Active Inactive
115 2 i3computer black 444500 Delet Edit update Active Inactive
116 1 samsung black 32000 Delet Edit update Active Inactive
117 1 samsung black 32000 Delet Edit update Active Inactive
118 2 hp black 16000 Delet Edit update Active Inactive
119 1 samsung black 16000 Delet Edit update Active Inactive
120 5 myproject nila 19191919 Delet Edit update Active Inactive
121 1 samsung hala 2323 Delet Edit update Active Inactive
122 1 samsung hala 2323 Delet Edit update Active Inactive
123 2 i9 koibhi 3214 Delet Edit update Active Inactive
124 1 hp black 32000 Delet Edit update Active Inactive
125 3 hp black 16000 Delet Edit update Active Inactive
126 1 hp black 32000 Delet Edit update Active Inactive
127 2 hp fvrt 16000 Delet Edit update Active Inactive
128 2 hp black 16000 Delet Edit update Active Inactive
129 2 hp black 32000 Delet Edit update Active Inactive
130 2 koibhi koibhi 1234 Delet Edit update Active Inactive
131 2 samsung black 16000 Delet Edit update Active Inactive
132 2 i3computer black 16000 Delet Edit update Active Inactive
133 1 samsung black 16000 Delet Edit update Active Inactive
134 1 samsung black 16000 Delet Edit update Active Inactive
135 1 samsung black 16000 Delet Edit update Active Inactive
136 1 hp black 16000 Delet Edit update Active Inactive
137 1 hp Blue 32000 Delet Edit update Active Inactive
138 1 samsung black 16000 Delet Edit update Active Inactive
139 1 samsung black 16000 Delet Edit update Active Inactive
140 1 samsung Blue 16000 Delet Edit update Active Inactive
141 1 hp black 16000 Delet Edit update Active Inactive
142 1 samsung black 16000 Delet Edit update Active Inactive
143 2 samsung black 16000 Delet Edit update Active Inactive
144 2 samsung black 32000 Delet Edit update Active Inactive
145 1 hp black 16000 Delet Edit update Active Inactive
146 1 samsung black 16000 Delet Edit update Active Inactive
147 2 samsung black 16000 Delet Edit update Active Inactive
148 1 samsung Blue 12000 Delet Edit update Active Inactive
149 1 samsung Blue 32000 Delet Edit update Active Inactive
150 1 hp Blue 32000 Delet Edit update Active Inactive
151 1 samsung black 16000 Delet Edit update Active Inactive
152 2 samsung black 16000 Delet Edit update Active Inactive
153 1 samsung black 32000 Delet Edit update Active Inactive
154 3 hp Blue 16000 Delet Edit update Active Inactive
155 2 samsung black 16000 Delet Edit update Active Inactive
156 2 samsung black 16000 Delet Edit update Active Inactive
157 1 samsung black 16000 Delet Edit update Active Inactive
158 1 samsung black 16000 Delet Edit update Active Inactive
159 2 hp black 16000 Delet Edit update Active Inactive
160 1 hp black 16000 Delet Edit update Active Inactive
161 1 hp black 16000 Delet Edit update Active Inactive
162 1 hp black 16000 Delet Edit update Active Inactive
163 2 md black 16000 Delet Edit update Active Inactive
164 1 hp black 16000 Delet Edit update Active Inactive
165 1 samsung black 16000 Delet Edit update Active Inactive
166 1 hp black 16000 Delet Edit update Active Inactive
167 1 hp black 16000 Delet Edit update Active Inactive
169         Delet Edit update Active Inactive
170         Delet Edit update Active Inactive
 
aspx code:
  1. <asp:GridView ID="grd" runat="server" AutoGenerateColumns="false" OnRowEditing="grd_RowEditing" OnRowUpdating="grd_RowUpdating" OnRowCommand="grd_RowCommand" OnSelectedIndexChanged="grd_SelectedIndexChanged">  
  2. <Columns>  
  3. <asp:BoundField DataField="pid" HeaderText="ID" />  
  4. <asp:TemplateField HeaderText="Cetagory">  
  5. <ItemTemplate>  
  6. <%#Eval("category") %>  
  7. </ItemTemplate>  
  8. </asp:TemplateField>  
  9. <asp:TemplateField HeaderText="Name">  
  10. <ItemTemplate>  
  11. <%#Eval("name") %>  
  12. </ItemTemplate>  
  13. </asp:TemplateField>  
  14. <asp:TemplateField HeaderText="Color">  
  15. <ItemTemplate>  
  16. <%#Eval("color") %>  
  17. </ItemTemplate>  
  18. </asp:TemplateField>  
  19. <asp:TemplateField HeaderText="Price">  
  20. <ItemTemplate>  
  21. <%#Eval("price") %>  
  22. </ItemTemplate>  
  23. </asp:TemplateField>  
  24. <asp:TemplateField HeaderText="Click_it">  
  25. <ItemTemplate>  
  26. <asp:LinkButton ID="lnkbtndelt" runat="server" CommandName="delt" CommandArgument='<%#Eval("pid") %>' Text="Delet" />  
  27. </ItemTemplate>  
  28. </asp:TemplateField>  
  29. <asp:TemplateField HeaderText="Click_It">  
  30. <ItemTemplate>  
  31. <asp:LinkButton ID="lnkbtnedit" runat="server" CommandName="edt" CommandArgument='<%#Eval("pid") %>' Text="Edit" OnClick="btnedit_Click" />  
  32. </ItemTemplate>  
  33. </asp:TemplateField>  
  34. <asp:TemplateField HeaderText="Click_It">  
  35. <ItemTemplate>  
  36. <asp:LinkButton ID="lnkbtnupd" runat="server" CommandName="upd" CommandArgument='<%#Eval("pid") %>' Text="update" OnClick="lnkbtnupd_Click" />  
  37. </ItemTemplate>  
  38. </asp:TemplateField>  
  39. <asp:TemplateField HeaderText="Status">  
  40. <ItemTemplate>  
  41. <asp:LinkButton ID="lbtactive" runat="server" Text="Active" OnClick="lbtactive_Click"></asp:LinkButton>  
  42. <asp:LinkButton ID="ibinactive" runat="server" Text="Inactive" OnClick="ibinactive_Click"></asp:LinkButton>  
  43. </ItemTemplate>  
  44. </asp:TemplateField>  
  45. </Columns>  
  46. </asp:GridView>  
cs code:
  1. private void active(string val, string code)  
  2. {  
  3. SqlCommand cmd = new SqlCommand("update products set status = '" + val + "' where pid = '" + code + "'", con);  
  4. con.Open();  
  5. cmd.CommandType = CommandType.Text;  
  6. cmd.ExecuteNonQuery();  
  7. con.Close();  
  8. }  
  9. protected void lbtactive_Click(object sender, EventArgs e)  
  10. {  
  11. active("1", grd.Rows[((GridViewRow)((sender as Control)).NamingContainer).RowIndex].Cells[0].Text);  
  12. }  
  13. protected void ibinactive_Click(object sender, EventArgs e)  
  14. {  
  15. int Index = ((GridViewRow)((sender as Control)).NamingContainer).RowIndex;  
  16. active("0", grd.Rows[Index].Cells[0].Text);  
  17. }  
  18. }  
plz rply as soon as possible
thank you

Answers (1)